javascript - do events registered with angular.element get removed by $destroy? -


i've read angular listeners ($scope.$on) automatically removed $destroy. , i've read outside event handlers jquery ($(document).on) need manually removed.

does know angular.element falls paradigm?

a team member wrote angular.element(document).on('event', () => );. need manually remove event in $ondestroy?

angular.element (jqlite) is tiny, api-compatible subset of jquery allows angularjs manipulate dom in cross-browser compatible way. jqlite implements commonly needed functionality goal of having small footprint.

directive link functions use attach event listeners elements other directive's own element need unregister listeners when directives element destroyed.

function postlink(scope, elem, attrs) {      $document.on('event', documenteventhandler);      scope.$on("$destroy", function() {         $document.off('event', documenteventhandler);     });      function documenteventhandler(event) {         console.log(event.target);         //other code here     }); } 

to facilitate unit testing, inject angularjs $document service instead of using angular.element(document).


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -