Reputation: 5
How can we change the value of model defined in $rootScope
before leaving the current scope in AngulrJS.
for example if the value of $rootScope.isPresent = true
in
../testMe url. And if we hit another url with the same $rootScope
then how can we change the value of $rootScope.isPresent
variable before displaying the view and initialing controller of new URL.
Upvotes: 0
Views: 47
Reputation: 598
If you want to execute a block of code before changing states that lead to changing scopes, you can use:
$scope.$on("$destroy", function()
{
// your code goes here
});
AngularJS automatically fires a $destroy event when it tries to destroy the scope, which lets your code execute before leaving this state.
Upvotes: 1