Removing Event Listeners in Angular JS

386 views
Skip to first unread message

user12345

unread,
Nov 9, 2015, 4:03:37 AM11/9/15
to AngularJS

I am using the below event listener in my custom directive code to execute certain logic once that event is triggered.

element.on("change", function(e) {
//Logic goes here
}

I want to know whether do we need to manually destroy these listeners or will angular destroys these listeners. If we need to manually remove, Could you help me how to remove these event listeners.?


Sander Elias

unread,
Nov 9, 2015, 5:58:28 AM11/9/15
to AngularJS
Hi User12345,

element.on('$destroy',....)

Not sure if it's needed at all. this is from the docs:
  • $destroy - AngularJS intercepts all jqLite/jQuery's DOM destruction apis and fires this event on all DOM nodes being removed. This can be used to clean up any 3rd party bindings to the DOM element before it is removed.
That implies that everything you do in angular itself will get's removed automaticly.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages