Skip to content

Instantly share code, notes, and snippets.

Created November 6, 2014 18:24
Show Gist options
  • Save anonymous/4eacf74771c7b1e87638 to your computer and use it in GitHub Desktop.
Save anonymous/4eacf74771c7b1e87638 to your computer and use it in GitHub Desktop.
One path returns a promise and the other a value
var saved_options = {};
function getOptions(myOption){
if(saved_options[myOption]){
return saved_options[myOption]
}
var deferred = $q.defer();
$http({method: 'GET', url:'someUrl'}).then(function(data){
saved_options[myOption] = data.data;
deferred.resolve(data.data);
});
return deferred.promise;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment