Well, this may be a long post, but please do not click, you may know a simple answer.
Happening:
Suppose you have created an angular application in which people log in, perform some operations, and then log out again. The application will collect data from the API using the factory and the service, and in order to make the download applicationeven faster, you will save this data in such variables:
app.factory("divisionService", function (api, $http, $q) {
var division = {};
var divisionArray = [];
var mergedUserList = [];
return {
getList: function () {
var d = $q.defer();
if (divisionArray <= 0) {
$http.get(api.getUrl('divisionWithUsers', null))
.success(function (response) {
divisionArray = response;
d.resolve(divisionArray);
});
}
if (divisionArray.length > 0) {
d.resolve(divisionArray);
}
return d.promise;
},
This ensures that if a user tries to use a controller that uses divisionService, then that user will instantly receive data if it is already selected.
Problem:
, ( /) . factory, , , , , , !
angular singletons, , .
: ", ", , .
, : ? , angular ?