So I have two factories in angular, one that is user-related (is user logged-in? talk with the back-end and log her in)
app.factory('userFactory', function($window, $location, $http) {
var loggedUser = {};
loggedUser.isLogged = false;
loggedUser.check = function() {
if($window.sessionStorage.user) {
this.isLogged = true;
} else {
this.isLogged = false;
}
}
loggedUser.doLogin = function (theData) {
var promise = $http({method: 'POST', url: 'http://whatevah/login', data: theData});
return promise;
}
return loggedUser;
});
and one that is interceptor-related (send a token and grab the answer to see if user is logged in).
app.factory('tokenFactory', function($q, $window, $http) {
return {
request: function(config) {
config.headers = config.headers || {};
if ($window.sessionStorage.token) {
$http.defaults.headers.common['mytoken'] = $window.sessionStorage.token;
}
return config || $q.when(config);
},
response: function(response) {
return response || $q.when(response);
}
};
});
They both have $http
injected, that causes this error
Circular dependency found: $http <- tokenFactory<- $http <- userFactory
Its weird to me that two different factories in angular cannot have the same injection, since the factories have different names and do different things
How can I fix this?
Thanks