I have developed a directive using TypeScript. Here is an example of the code:
'use strict';
module App.Directives {
interface IPageModal extends ng.IDirective {
}
interface IPageModalScope extends ng.IScope {
//modal: any;
}
class PageModal implements IPageModal {
static directiveId: string = 'pageModal';
restrict: string = "A";
constructor(private $parse: IPageModalScope) {
}
link = (scope: IPageModalScope, element, attrs) => {
element.on('click', function (event) {
event.preventDefault();
var options = {
backdrop: 'static',
keyboard: false
};
event.openModal = function () {
$('#' + attrs['targetModal']).modal(options);//error
};
event.showModal = function () {
$('#' + attrs['targetModal']).modal('show');//error
};
event.closeModal = function () {
$('#' + attrs['targetModal']).modal('hide');//error
};
var fn = this.$parse(attrs['pageModal']);
fn(scope, { $event: event });
});
}
}
//References angular app
app.directive(PageModal.directiveId, ['$parse', ($parse) => new PageModal($parse)]);
}
Every time I try to call the jQuery Bootstrap .modal function, I encounter an error. Can someone help me with calling this function correctly?
$('#' + attrs['targetModal']).modal('hide'); //error line of code