I am developing an angularjs app as a part of my angularjs learning. I have controllers and from there I am calling service layers.
leagueManager.service(&quo
This should work fine:
myApp.factory('mainFactory',['$http',function($http){
var mainFactory = {};
mainFactory.getRandomUser = function(){
var promise;
if(!promise){
promise = $http.get('http://api.randomuser.me/').success(function(d){
return d;
});
return promise;
}
};
mainFactory.getRandomImage = function(){
var promise;
if(!promise){
promise = $http.get('http://lorempixel.com/400/200/').success(function(d){
return d;
});
return promise;
}
};
return mainFactory;
}]);