javascript - In an Angular directive, how do you reapply an event listener after the event has been removed? -
this might result of me lacking knowledge in angular , if so, forgive me in advance if case.
in angular, suppose have directive bound element attribute.
<div my-directive></div>
in directive, have click event remove click event itself.
app.directive("mydirective", function() { return { link: function(scope, ele, attr, ctrl) { ele.on("click", function() { ele.off("click"); console.log("click event removed"); }); } } });
i want set click event on same div directive again (let's after button clicked). how accomplish this?
you can use this-
app.directive("mydirective", function() { return { link: function(scope, ele, attr, ctrl) { ele.on("click", function() { ele.unbind("click"); console.log("click event removed"); angular.element(ele).bind("click"); }); } } });
Comments
Post a Comment