AngularJS路由变化 监听方法

#使用AngularJS时,当路由发生改变时,我们需要做某些处理,此时可以监听路由事件,常用的是$routeStartChange, $routeChangeSuccess

##使用场景:在路由配置文件routeConfig.js,对路由跳转进行特殊处理经常用到

 app.run(['$rootScope', '$location', function($rootScope, $location) {
        /* 监听路由的状态变化 */
        $rootScope.$on('$routeChangeStart', function(evt, next, current){
          console.log('route begin change');
        }); 
        $rootScope.$on('$routeChangeSuccess', function(evt, current, previous) {
          console.log('route have already changed :'+$location.path());
        }); 
    }])

  

猜你喜欢

转载自www.cnblogs.com/yaohe/p/10672191.html