I am using a directive that does some initialization logic in its link function
One thing thats done here is listenening to service changes via scope.$watch
How do i correctly remove and readd this $watch if the view is reloaded from cache?
using
scope.$on("$destroy", function() {
console.log("destroy");
});
does not work, the event is never triggered, i therefore can not remove the callback from the watch set previously
what i have so far:
-
the link function is called every time the view enters, automatically, i could store the watch callback somewhere globally/service and remove it in here, not a very nice solution
-
the scope.$on(“destroy”) does not work in a directive, i have no idea why
-
the watches are bound to the directives scope, it doesnt matter if its an isolated scope or not: the watch is never removed
I’ll try to create a codepen, for the time being it would help me to know if theres any way to listen to the view events (enter and beforeEnter) that affect a controller that is bound to a template with the directive in it