For example, I have a custom directive that I use like this:
<my-directive ng-if="showThis"></my-directive>
I need to perform some DOM-manipulations and attach/remove event handlers when showThis
that defined in rootScope turns to true or false. It might happens many times during workflow. That's why I have some questions:
Can I handle the change of
ng-if
?Where should I do this: inside link function or controller function of myDirective?
Does I really need to kill and reattach event listeners each time to avoid memory leaks? Or AngularJS will do it for me?
Will link and controller functions be called each time, when
ng-if
turns to true?