Angularjs$resource发送后查询字符串不是JSON对象(Typescript)
当我编写自定义操作$resource时,如下所示:Angularjs$resource发送后查询字符串不是JSON对象(Typescript),angularjs,typescript,angular-resource,Angularjs,Typescript,Angular Resource,当我编写自定义操作$resource时,如下所示: getEntityResource(): ng.resource.IResourceClass<IEntityResource> { let addAction: ng.resource.IActionDescriptor = { method: 'POST', url: 'http://localhost:8085/api/entity/add' }
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
电话发送方式如下:
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请求
我错过了什么
谢谢。看一看
您的问题是,您将数据作为第二个参数传递。要将数据作为JSON对象传递,必须执行以下操作:
$resource("http://localhost:8085/api/entity/:entityId",
{},
{params: {id: '@id'}...}
);
你有什么错误吗?问题是什么?它正在发送一个查询字符串/add?id=0而不是JSON对象。