Skip to content

Instantly share code, notes, and snippets.

@abner
Forked from djavier/myAJResource.js
Last active August 29, 2015 14:25
Show Gist options
  • Save abner/1271cb3725971b55b4b9 to your computer and use it in GitHub Desktop.
Save abner/1271cb3725971b55b4b9 to your computer and use it in GitHub Desktop.
var module = angular.module( 'my.resource', [ 'ngResource' ] );
module.factory( 'Resource', [ '$resource', function( $resource ) {
return function( url, params, methods ) {
var defaults = {
update: { method: 'put', isArray: false },
create: { method: 'post' }
};
methods = angular.extend( defaults, methods );
var resource = $resource( url, params, methods );
resource.prototype.$save = function() {
if ( this.id === undefined ) {
return this.$create.apply(this, arguments);
}
else {
return this.$update.apply(this, arguments);
}
};
return resource;
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment