I am using a factory to get JSON data after a user logs in. If the username and password is correct it should pull JSON data from the api link. I have several controllers in my application that will need to use this data. I want to avoid sharing this factory with all my controllers because I do not want to keep "GETTING" data. I only want this factory to be used with the login controller.
How can I save the data from 'dummyData' and then all the other controllers can use that data without having to make a 'GET' request every time?
angular.module('ciscoImaDashboardApp').factory('dummyData', ['$q', '$http', function($q, $http) {
var apiServices = {};
apiServices.saveData = function(user,password) {
var deferred = $q.defer();
var req = $http({
method: 'GET',
url: 'http://magainteractive.com/prototypes/cisco-ima-dashboard/cms/web/api/login/login/?username='+user+'&password='+password
});
req.success(function(response) {
deferred.resolve(response);
});
req.error(function(err) {
console.log("there was an error: "+err);
deferred.reject(err);
});
return deferred.promise;
}
return apiServices;
}]);