0
votes

So, I have this function for handling routing errors:

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");
      }

   });
}]);

Not super complex, I know.

But whenever I run it, I get the issue that the $state.go method is coming back as undefined. Am I missing something?

1

1 Answers

0
votes

If you're going to explicitly inject $state, you have to include it in both the array and in the function's arguments, not just the latter.

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");
      }

   });
}]);