Reputation: 8765
I want to run a function on each route changes in angular.
Is there any event like OnRouteChange in angular?
Upvotes: 1
Views: 1575
Reputation: 21901
yes there are some events like,
$routeChangeStart
, $routeChangeSuccess
, $routeChangeError
, $routeUpdate
$routeChangeStart
-> Broadcasted before a route change. At this point the route services starts resolving all of the dependencies needed for the route change to occur. Typically this involves fetching the view template as well as any dependencies defined in resolve route property. Once all of the dependencies are resolved $routeChangeSuccess is fired.
for EX:
app.run(function($rootScope, $location) {
$rootScope.$on('$routeChangeStart', function(event, next, current) {
});
$rootScope.$on('$routeChangeSuccess', function () {
});
$rootScope.$on('$routeChangeError', function () {
});
})
here is the DOC
here is a good article.
Upvotes: 3