Skip to content

Instantly share code, notes, and snippets.

@chandermani
Created February 14, 2014 05:44
Show Gist options
  • Save chandermani/8996375 to your computer and use it in GitHub Desktop.
Save chandermani/8996375 to your computer and use it in GitHub Desktop.
app.factory(‘Items’,function($http) {
var items = [];
return {
list: function() {
var defer=$q.defer();
if (items.length == 0) { // items array is empty so populate it and return list from server to controller
$http.get(‘/?items’).then(function(response) {
items = response.data.items;
defer.resolve(items);
});
}
else {
defer.resolve(items);
}
return defer.promise;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment