I am trying to refactor my AngularJS application and introduce a login service. Currently my controller has methods like login(), logout(), getCurrentUser(), which make http requests and handle the user object. I want to move these functions into a service, because I need to call the getCurrentUser() method from multiple controllers.
I have written the following service:
angular.module('common.login', []).
factory('loginService', function ($http) {
return {
user: null,
error: null
};
});
So at the moment the service is not doing anything. However I get an error:
Uncaught Error: Circular dependency: loginService <- $http
If I remove the $http dependency from the callback function, then the service works. I have trouble understanding why there is a circular dependency. The loginService factory is injected into two places: A **main module's config callback ** and a **login module's controller callback **. The config callback configures a http interceptor, the login controller also uses the http services.