Created
February 14, 2014 05:44
-
-
Save chandermani/8996375 to your computer and use it in GitHub Desktop.
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
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