首页 > 解决方案 > 向 Angular 4 中的删除请求发送有效负载

问题描述

我的添加发布请求正常工作,但是当我尝试将相同的有效负载传递给删除请求时,我收到错误消息。api 是相同的值并接受相同的有效负载。只是一个不同的请求 POST 和 DELETE。

每个有效负载看起来像这样

{
 jim : 1234
}

这是我的 add() / POST 请求(工作)

add() {
      let jim = {
        jim: this.htmlvalue
      };
      return this.myApiService.create({},
        jim).subscribe(response => {
          console.log('response', response);
          this.reset();
        },error => {
          console.log('error', error);
        }
      );
    }

这就是我正在尝试处理我的删除请求

delete(jim) {
      let jim = {
        jim: this.htmlvalue
      };
      return this.myApiService.remove({},
       jim).subscribe(response => {
          console.log('response', response);
          this.reset();
        },error => {
          console.log('error', error);
        });
    }

错误信息是

Argument of type '{}' is not assignable to parameter of type 'string'.

这与删除请求中的 .remove({}, jim) 有关

标签: javascriptangularapi

解决方案


推荐阅读