Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
908 views
in Technique[技术] by (71.8m points)

angularjs - Send Request Body on $resource

I take a look on Angular API for $resource and I didn't find some way to send a Request Body to a RESTful service.

I know this is possible using $http approach, like here, so, is it also possible to do using $resource?

Apparently this is the options for $resource.

action – {string} – The name of action. This name becomes the name of the method on your resource object.

method – {string} – HTTP request method. Valid methods are: GET, POST, PUT, DELETE, and JSONP

params – {object=} – Optional set of pre-bound parameters for this action.

isArray – {boolean=} – If true then the returned object for this action is an array, see returns section.

At the moment I didn't found any way to send a request payload containing an JSON object.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Building on @gargc's answer, you can pass parameters and a body to a resource's method:

myResource.save({ param: myParam }, myObject);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...