0

I created an angular module that uses the current $location.path to load content dynamically. I set up the module config like this:

var app = angular.module('App',['ngRoute']).
config(
    ['$routeProvider','$locationProvider','$sceProvider'],
    function($routeProvider,$locationProvider,$sceProvider){
        $routeProvider.
            otherwise({
                templateUrl: 'views/_view.html',
                controller: 'ViewCtr',
                resolve: {
                    load: function(dataFactory,$route,$location){
                        return dataFactory.load($location.path());
                    }
                }
            });
        $locationProvider.html5Mode(true);
        $sceProvider.enabled(false);
});

It works perfectly although when I set $scope.$on('$routeChangeStart') to add some animations when content is loading, it fires the route change twice. I believe it's because I set the routeProider as "otherwise" and it redirects every time.

Can you correct me if I am wrong or tell me if and how it is possible to differentiate from a real route change and a redirect? Thank you.

4

1 回答 1

0

切换到使用 $routeChangeSuccess 而不是 $routeChangeStart。我还会研究 ng-animate ( https://docs.angularjs.org/api/ngAnimate ),因为它可能能够比您监听 routeChanges 更好地处理它。

于 2014-11-12T13:40:21.560 回答