Reputation: 57
When I write a custom action $resource like this:
getEntityResource(): ng.resource.IResourceClass<IEntityResource> {
let addAction: ng.resource.IActionDescriptor = {
method: 'POST',
url: 'http://localhost:8085/api/entity/add'
}
return <ng.resource.IResourceClass<IEntityResource>>
this.$resource("http://localhost:8085/api/entity/:entityId", { id: '@id' }, {
add: addAction,
});
and call it from the controller like this:
this.$mdDialog.hide(this.dataService
.getEntityResource()
.add(this.entity,
() => this.$state.reload()
));
the call is sending like this:
Request URL:http://localhost:8085/api/entity/add?id=0
The webApi action is accepting entity object as parameter not an id:
[HttpPost]
public Entity Add(Entity entity)
The problem is that it sends the post request with a string parameter (?id=0) and not JSON object.
What am I missing?
Thank you.
Upvotes: 1
Views: 1257
Reputation: 2683
Take a look at $resource.
Your problem is, that you pass the data as second parameter. To pass the data as a JSON object you must do the following:
$resource("http://localhost:8085/api/entity/:entityId",
{},
{params: {id: '@id'}...}
);
Upvotes: 1