0

所以,我有这个功能来处理路由错误:

angular.module('player-tracker').run(['$rootScope', '$location', function($rootScope, $state) {
    $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, rejection) {
      if (rejection === 'AUTH_REQUIRED') {
        $state.go("/home");
      }

   });
}]);

不是很复杂,我知道。

但是每当我运行它时,我都会遇到 $state.go 方法返回未定义的问题。我错过了什么吗?

4

1 回答 1

0

如果要显式注入 $state,则必须将它包含在数组和函数的参数中,而不仅仅是后者。

angular.module('player-tracker').run(['$rootScope', '$state', function($rootScope, $state) {
    $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, rejection) {
      if (rejection === 'AUTH_REQUIRED') {
        $state.go("/home");
      }

   });
}]);
于 2015-08-30T02:11:02.050 回答