ngResource appends POST parameters to url

angularjs, ngresource

Solution

I think you're conflicted on how to use `$resource`. You should create $resource instances as if they were models and set the attributes on the object that you want to POST.

With your `Apples` $resource defined as above:

var apple = new Apples();

apple.color = ...
apple.name = ...
apple.tree_id = ...

apple.$create()

Or you could just use the $resource class directly:

Apples.create({
    apple.color: ...
    apple.name: ...
    apple.tree_id: ...
});

Finally, $resource has the built-in `$save()` that uses POST which you can use instead of creating a custom `$create()` action.

Problem

I have an angular service that looks like this. Here i am making a POST request. ``` .factory("Apples", function ($resource, HOST) { return $resource( HOST + "/apples", {}, { create: { method: 'POST', params: { tree_id: '@treeId', name: '@name', color: '@color' } } } ); }) ``` The problem is that the above service makes a POST request and sends the `params` data as form data but also appends the `params` data to the url as query string. Can i avoid that?

Original source