Created
June 6, 2014 14:42
-
-
Save adjohu/204514290ccde1b2be47 to your computer and use it in GitHub Desktop.
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
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