Skip to content

Instantly share code, notes, and snippets.

@AlexVKO
Created July 13, 2015 05:16
Show Gist options
  • Save AlexVKO/3ccb660802cf8d0edafe to your computer and use it in GitHub Desktop.
Save AlexVKO/3ccb660802cf8d0edafe to your computer and use it in GitHub Desktop.
Make $resource respond to PUT or POST with $save
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 ) {
return this.$create();
}
else {
return this.$update();
}
};
return resource;
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment