Fire callback when changing a route (animations, loaders, etc.) In AngularJS

I am new to AngularJS.

When the route is changed, ng-view changes the content. What I would like to be able to do is to intercept some kind of behavior when changing the route.

  • I would like to be able, for example, to animate the representation that we are leaving (disappearing and moving to the left), and when the next view is easily accessible, it fades and shifts the view. This can be done by adding a class to the body when loading a route and deleting a class when changing a route successfully

  • I would like the view to the right of the current view, so that when one moves forward, the next view first loads to the right of the current one, then the viewport slides to the right, so that the current view slides almost from the view and the next picture in the view (Windows -phone, like navigation on canvas)

Is $ routeProvider the right place to do this?

Are there any gurus who could point me in the right direction?

+8
angularjs angularjs-directive
source share
2 answers

After several more studies, events were released for this purpose.

$scope.$on('$routeChangeStart', function(scope, next, current){ //... }); $scope.$on('$routeChangeSuccess', function(scope, next, current){ //... }); 

If the problem is to revive something (for example, when changing the route), I recommend using ngAnimate. Read more about it here.

+11
source share

You can set the clock at the main area level to catch a change in location:

 $rootScope.$watch(function { return $location.path(); }, function(newValue, oldValue) { if (newValue != oldvalue) { // here you can do your tasks } else { } }, true); 
+3
source share

All Articles