How to unload the AngularJS directive when changing templates

I have a web application built using AngularJS and it includes various routes / controllers / views / etc.

Several views require directives, which I include. I noticed that when changing the route and loading a new template, the directives from the old template continue to work. Just by creating a directive that will be written to the console, you will continue to register it when loading a new route.

Is there any way to avoid this? It seems to be a waste of memory.

+4
source share
1 answer

Remember to cancel events related to the directive!

. , :

$scope.$on('$destroy',function() { angular.element($window).unbind('resize'); });

+5

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


All Articles