【发布时间】:2016-05-17 17:04:43
【问题描述】:
当我像这样编写自定义操作 $resource 时:
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,
});
并像这样从控制器调用它:
this.$mdDialog.hide(this.dataService
.getEntityResource()
.add(this.entity,
() => this.$state.reload()
));
电话是这样发送的:
Request URL:http://localhost:8085/api/entity/add?id=0
webApi 操作接受实体对象作为参数而不是 id:
[HttpPost]
public Entity Add(Entity entity)
问题在于它使用字符串参数 (?id=0) 而不是 JSON 对象发送 post 请求。
我错过了什么?
谢谢。
【问题讨论】:
-
您是否遇到任何错误?有什么问题?
-
它发送的是查询字符串 /add?id=0 而不是 JSON 对象。
标签: angularjs typescript angular-resource