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

Popular posts from this blog

How to check data type in C++? -

javascript - Is getTimezoneOffset() stable during daylight saving transition? -

sql server - SQL Query returns one result, does not return 0 or NULL result -