3

When i put $state there i get this error...how can i fix it?

I want to use $state to navigate to another page but i dont know how ? Any suggestion ? Is there any other way to navigate user to another page ?

 app.factory('mainAuthInterceptorService', ['$q','$state', '$injector', '$location', 'localStorageService', function ($q,$state, $injector, $location, localStorageService) {....}

im using this

 authService.logOut();

And now i need to redirect user to another page ...

None
  • 8,817
  • 26
  • 96
  • 171
  • is $state being injected into `localStorageService` also? `authService` is not shown injected in controller. – charlietfl Jul 14 '15 at 15:32

1 Answers1

1

One simple fix would be to use the $injector service to get a reference to the $state service, like so:

    app.factory('mainAuthInterceptorService', ['$q', '$injector', '$location', 'localStorageService',
      function($q, $injector, $location, localStorageService) {
        var $state = $injector.get('$state'); // inject state manually

        ... // your interceptor logic
      }

You can then use the $state object like usual.

There is a similar question created by another user with a great answer that explains the issue in depth: Injecting $state (ui-router) into $http interceptor causes circular dependency

Community
  • 1
  • 1
Ruben Cordeiro
  • 322
  • 3
  • 6