I've been working with TypeScript in an Angular project.
Recently, I created a directive that consists of a div containing text and a close button with the class name 'block-close'.
Now, my challenge is to implement a click function for the close button within the directive.
How can I add a click event to a button that is nested inside the directive?
I've attempted various approaches like:
angular.element('.block-close').on('click', function(){
alert('Clicked!');
});
angular.element(document).find('.block-close').on('click', function(){
alert('Clicked!');
});
(() => {
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('Clicked!');
});
};
}
angular.module('myMod').directive('myDirective', () => new MyDirective());
})();