0
私はtypescriptを使って指令を書いた。コードはこのようになります。jsceryライブラリ関数をtypescriptに書き込む
'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)]);
}
jqueryブートストラップ.modal関数を呼び出すと、エラーが発生します。この関数を以下のように呼び出すにはどうすればいいですか?
$( '#' + attrs ['targetModal'])。あなたは型定義を必要とするコンパイル時エラーの場合は.modal機能ブートストラップコードの//エラー行
あなたは私のコードを書き換えることはできますか? – Shohel
私のアドオンであなたのコードはそのまま動作します – basarat
どうすればこの行を$( '#' + attrs ['targetModal'])と呼ぶことができますか。 – Shohel