When visibility naturally collapses in the angularjs lifecycle

I see this type of code in angular modules

scope.$on('$destroy', function(){ //undind listener here }); 

I understand that whenever a scope needs to be destroyed, it emits a $destroy event, allowing you to clear any code that might continue to work after destroying a scope that would create memory leaks.

My question is when a region is naturally destroyed in an angularjs application. All the documentation I can find on the website is that you can manually call $destroy to delete the area, but this seems to suggest that this will happen at some point automatically. When it will be?

+6
source share
1 answer

The scope is bound to HTML elements at compile time. $ compile requires an area to compile the element. Elements can be nested. Some of them inherit another area.

The scope is deleted when items are removed from the DOM.

To be precise: the $destroy handlers are called on jQuery.cleanData , which AngularJS redefines and calls after it performs its cleanup, aka acting in the destruction of the area.

cleanData function is called when an element is removed from the DOM.

What is the purpose of jQuery clean and cleanData methods?

0
source

Source: https://habr.com/ru/post/975540/


All Articles