Created
September 2, 2014 07:20
-
-
Save yelvert/3f536e690c7c1f419334 to your computer and use it in GitHub Desktop.
Angular resource/api combination
This file contains 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
(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