Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs$resource发送后查询字符串不是JSON对象(Typescript)_Angularjs_Typescript_Angular Resource - Fatal编程技术网

Angularjs$resource发送后查询字符串不是JSON对象(Typescript)

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' }

当我编写自定义操作$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
电话发送方式如下:

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对象。