Skip to content

Instantly share code, notes, and snippets.

@owenmead
Created March 22, 2013 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owenmead/5223009 to your computer and use it in GitHub Desktop.
Save owenmead/5223009 to your computer and use it in GitHub Desktop.
Basic Angular service talking to a resource
angular.module('myApp')
.factory('people', function($resource, $q) {
var people_resource = $resource(myApp.API_BASE_URL + '/people/:personId');
// Public API here
return {
getList: function() {
var deferred = $q.defer();
var people = people_resource.query(function() {
angular.forEach(people, function(obj) {
obj.created = new Date(obj.created);
obj.modified = new Date(obj.modified);
});
deferred.resolve(people);
});
return deferred.promise;
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment