Skip to content

Instantly share code, notes, and snippets.

@adjohu
Created June 6, 2014 14:42
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 adjohu/204514290ccde1b2be47 to your computer and use it in GitHub Desktop.
Save adjohu/204514290ccde1b2be47 to your computer and use it in GitHub Desktop.
var wrappedResourceMethods = [
'get', 'query'
];
var wrappedResource = function (resource) {
_.each(wrappedResourceMethods, function (method) {
if (_.has(resource, method)) {
var originalMethod = resource[method];
resource[method] = function () {
var result = originalMethod.apply(this, arguments);
result.is_loading = true;
if (result.$promise) {
result.$promise.then(function () {
result.is_loading = false;
});
}
return result;
};
}
});
return resource;
};
YourAppServices.factory('service', ['$resource', 'API_ENDPOINT',
function($resource){
return wrappedResource($resource('url'...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment