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

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -