I have one factory like this :
app.factory('LoginFactory', [ '$scope', '$http', function($scope, $http) {
var urlBase = "http://localhost:8080/app";
var fact = {};
fact.login = function(userinfo) {
return $http({
method : 'POST',
url : urlBase + '/login',
data : userinfo,
headers : {
'Content-Type' : 'application/json',
'Accept' : 'application/json'
}
});
};
fact.validate = function(sessionId) {
return $http({
method : 'GET',
url : urlBase + '/validate?sessionId=' + sessionId,
});
};
return fact;
} ]);
And Another factory like this :
app.factory('LoginService', [
'Credentials',
function(Credentials, $location, LoginFactory) {
var fact = {};
fact.isLoggedin = function() {
var result = false;
LoginFactory.validate(Credentials.sessionId).success(
function(data, status, headers, config) {
result = true;
}).error(function(data, status, headers, config) {
result = false;
});
return result;
};
fact.authenticate = function(userinfo) {
LoginFactory.login(userinfo).success(
function(data, status, headers, config) {
Credentials = data;
$location.path('/home');
}).error(function(data, status, headers, config) {
$location.path('/login');
});
};
return fact;
} ]);
In the Browser Console I am getting the following error :
Error: LoginFactory is undefined
Can anyone please help me out with this error.
Thanks a lot in advance.
You're declaring your service using the array notation, taking the names of the dependencies to inject followed by the function defining the factory. But you said you only wanted to inject Credentials:
app.factory('LoginService', [
'Credentials',
function(Credentials, $location, LoginFactory) {
So angular only injects Credentials. The above should be replaced by
app.factory('LoginService', [
'Credentials', '$location', 'LoginFactory'
function(Credentials, $location, LoginFactory) {
To avoid those bugs, and the repetition of service names in the array and in the function, I strongly suggest using ngAnnotate in your build.