0
我在Angular中使用typescirpt。角度打字稿指令,在元素鏈接中查找div
我創建了一個指令,這只是一個div包含文本和一個類名「塊關閉」
我需要一個點擊功能添加到關閉按鈕關閉按鈕。
如何將點擊事件添加到指令中的按鈕。
像
angular.element('.block-close').on('click', function(){
alert('here');
});
angular.element(document).find('.block-close').on('click', function(){
alert('here');
});
(()=>{
class MyDirective implements ng.IDirective{
public restrict = 'E';
public scope = {};
public controller = 'MyController';
public controllerAs = 'myCtrl';
public bindToController = true;
public templateUrl = "mysite.html";
constructor(){
}
link = (scope, element, attrs) => {
angular.element('.block-close').on('click', function(){
alert('here');
});
};
}
angular.module('myMod').directive('myDirective',()=> new MyDirective());
})();