Two different animations for route changes

后端 未结 5 1610
感动是毒
感动是毒 2020-12-28 15:51

I have the following case: I\'m using the ui-router for the routing in my AngularJS application. In one route, there are five child states for different subscreens. I want t

5条回答
  •  时光取名叫无心
    2020-12-28 16:44

    I was attempting to do this same thing with ngRoute using $routeChangeSuccess but the problem I ran into was that the ng-leave animation would start before a digest cycle ran. The enter animation was always correct, but the leave animation was always the previous one.

    The solution that worked for me (Angular 1.57) was to wrap the $location.path() call in a $timeout. This makes sure a full digest runs before the animation is started.

    function goto(path) {
        if(nextIndex > currentIndex) {
          ctrl.transition = 'slide-out-left';
        } else {
          ctrl.transition = 'slide-out-right';
        }
        $timeout(function() {
          $location.path(path);
        });
      }
    

提交回复
热议问题