I came across this after reading the correct ways to clear $ scope event listeners in angularjs.
I listen to the event on $ rootScope in the application module launch block:
app.run(['$rootScope', function($rootScope){
$rootScope.$on('$stateChangeStart', function(event, toState, toParams){
});
}]);
Since $ scope is not available in the launch block, can I listen for the destroy event on $ rootScope instead?
So:
app.run(['$rootScope', function($rootScope){
var listenerFn = $rootScope.$on('$stateChangeStart', function(event, toState, toParams){
});
$rootScope.$on('$destroy', listenerFn);
}]);
I'm not sure I can do this by looking at various messages and documents on the Internet, since it does not look like $ rootScope has a destroy event. So what is the right approach here?
source
share