AngularJS Developer Question:
Download Questions PDF

Tell me when a scope is terminated, two similar “destroy” events are fired. What are they used for, and why are there two?


The first one is an AngularJS event, “$destroy”, and the second one is a jqLite / jQuery event “$destroy”. The first one can be used by AngularJS scopes where they are accessible, such as in controllers or link functions.

Consider the two below happening in a directive’s postLink function. The AngularJS event:

scope.$on(‘$destroy’, function () {
// handle the destroy, i.e. clean up.

element.on(‘$destroy’, function () {
// respectful jQuery plugins already have this handler.
// angular.element(document.body).off(‘someCustomEvent’);
The jqLite / jQuery event is called whenever a node is removed, which may just happen without scope teardown.

Download AngularJS Developer Interview Questions And Answers PDF

Previous QuestionNext Question
Tell me what are the differences between service and factory methods?Tell me what is the role of services in AngularJS and name any services made available by default?