Last active
May 18, 2016 02:15
-
-
Save drKnoxy/f023651aa42a805a0a417b86ae1f538d to your computer and use it in GitHub Desktop.
cacheing promises in angularJS so requests don't pile up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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