-2

How modify save method for put, if id specified and post if not?

I mean:

Posts.save({id: 1, content: "..."}) // PUT /posts/1
Posts.save({content: "..."}) // POST /posts
nkt
  • 181
  • 1
  • 9
  • Please read the [documentation](https://docs.angularjs.org/api/ngResource/service/$resource#creating-a-custom-put-request). Angular's documentation does a great job of showing how to complete common tasks and even shows how to properly unit test. – Dom Nov 04 '14 at 04:32

1 Answers1

1

It seems you cannot do that in normal way. If you want to update just create your own update function in resource like:

app.factory('Posts', ['$resource', function($resource) {
    return $resource('/posts/:id', null,
    {
        'update': { method:'PUT' }
    });
}]);

Here is document.

Tyler.z.yang
  • 2,402
  • 1
  • 18
  • 31