Skip to content

Instantly share code, notes, and snippets.

@yelvert
Created September 2, 2014 07:20
Show Gist options
  • Save yelvert/3f536e690c7c1f419334 to your computer and use it in GitHub Desktop.
Save yelvert/3f536e690c7c1f419334 to your computer and use it in GitHub Desktop.
Angular resource/api combination
(function() {
'use strict';
angular.module('someModule').factory('SomeResource', [
'$http',
function ($http) {
return $http.get('http://example.com/some_resources').then(function (res) {
return res.data;
});
}
]);
angular.module('someModule').factory('SomeResourceApi', [
'SomeResource',
function (SomeResource) {
return SomeResource.then(function (resources) {
return resourceFactory = {
all: function (){
return resources;
},
find: function (id) {
return _.where(resources, {id: id});
}
};
});
}
]);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment