Hello Friends, Some time we get stuck when a scope is terminated and found that two similar destroy events are triggered. Here we want to understand What and why are they two used for in angular js.
The first one is an Angular jS event, $destroy, and the second one is a jqLite / jQuery event $destroy. The first one can be used by Angular jS scopes where they are accessible, like as in controllers or link functions.
Lets see the two below happening in a directives function. The Angular jS event:
scope.$on($destroy, function () {
// some clean up code here
});
element.on($destroy, function () {
// jQuery already have this handler.
// angular.element(document.body).off(someCustomTestEvent);
});
The jqLite/jQuery event is triggered whenever a node is removed, which can just happen without scope teardown.
0 Comment(s)