Skip to content

Instantly share code, notes, and snippets.

@drKnoxy
Last active May 18, 2016 02:15
Show Gist options
  • Save drKnoxy/f023651aa42a805a0a417b86ae1f538d to your computer and use it in GitHub Desktop.
Save drKnoxy/f023651aa42a805a0a417b86ae1f538d to your computer and use it in GitHub Desktop.
cacheing promises in angularJS so requests don't pile up
angular.module('configModule')
.factory('timezoneService', ['configApiService', '$q',
function(configApiService, $q) {
var tzPromise = false;
var service = {
get: getTz,
};
return service;
////////////////////////
function getTz() {
if (!tzPromise){
var config = { path: 'general.store.timezone' };
tzPromise = configApiService.getPath(config).$promise
.then(function(response) {
return response.result.substr(3);
});
}
return tzPromise;
}
}
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment