$ State injection (ui-router) causes circular dependency
When I put $ state I get this error ... how can I fix it?
I want to use $ state to navigate to another page, but I donβt know how? Any suggestion? Is there any other way for the user to navigate 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 the user to another page ...
+3
source to share
1 answer
One simple solution would be to use the $ injector service to get a reference to the $ state service, e.g .:
app.factory('mainAuthInterceptorService', ['$q', '$injector', '$location', 'localStorageService',
function($q, $injector, $location, localStorageService) {
var $state = $injector.get('$state'); // inject state manually
... // your interceptor logic
}
Then you can use the $ state object as usual.
There is a similar question posted by another user with a great answer that explains the problem in detail: Including $ state (ui-router) in the $ http interceptor causes a circular dependency
+1
source to share