Ajv2324 Ajv2324 - 2 months ago 6x
AngularJS Question

With Angular $resource, how can I send a PUT request with URL params that aren't included in the payload?

$resource gives me nightmares. Right now I have something like this in my service:

makeCall: function(auth, data, new, old){
return this.resource(auth).putRequest({id: data.id, thing1: new, thing2: old}).$promise

resource: function(auth){
$resource(config.url, {id: '@id'}, {
putRequest: {
method: 'PUT',
params: {thing1: '@thing1', thing2: '@thing2'},
url: config.url + '/user/:id/update'
headers: {authorization: auth}

This sends a PUT request to the url as requested, with the id parameter being set correctly. However, the problem is that id also appears in the payload, when the payload needs to only consist of thing1 and thing2.


When calling a resource you can specify the urlParams and the formBody Params like so

resource(auth).putRequest({id: data.id}, {thing1: new, thing2: old}).$promise

The first Parameter is the urlParams and the second is the formBody, for more information look at the documentation