0

Having the following $resource service:

myService.factory('Phones', function ($resource) {
    return $resource('/api/Phones', { phoneName: '@phoneName' }, {
        submit: { method: 'POST', },
    });
});

Calling submit on the returned $resource object will post the phoneName as a parameter e.g. /api/Phones?phoneName=Nokia. However calling the same resource object with the GET method will also use the phoneName parameter as undefined e.g. /api/Phones?phoneName=undefined.

Is it possible to prevent the phoneName to appear for the GET method using the same $resource object?

Thanks!

1 Answer 1

1

Try changing your service to this:

myService.factory('Phones', function ($resource) {
    return $resource('/api/Phones', {}, {
        submit: { 
          method: 'POST'
        }
    });
});

That way you only define the paramater 'phoneName' on the 'submit' action and not all actions.

Edit: You don't need to define phoneName as a param in the $resource action.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer. Now if I call the service like this: Phones.submit({ phoneName: 'Nokia' }); it will no longer replace the @phoneName attribute instead it outputs: /api/Phones?phoneName=@phoneName Any idea how to solve this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.