Reputation: 1767
I have the following circular dependency:
$http
/ \
/ \
/ \
/ \
LoginManager------Interceptor
(service) (factory)
This Circular dependency only emerged after I added the code for Interceptor.
Interceptor
will call the logout function in LoginManager
in case a certain response
in intercepted.
From what I see, only solution is to move interceptor code inside the
LoginManager
service as ananonymous factory
Is there any better way?
Upvotes: 3
Views: 1428
Reputation: 2002
You can avoid the circular dependency by using the injector
service to get an instance of LoginManager
at runtime.
var loginManager = $injector.get('LoginManager');
Just make sure you use this code inside one of the methods of the interceptor (e.g responseError
) and not directly in your interceptor creation code.
Upvotes: 6