【问题标题】:Angular 2 Error Supplied parameters do not match any signature of call targetAngular 2错误提供的参数与调用目标的任何签名都不匹配
【发布时间】:2016-11-14 10:24:48
【问题描述】:

我试图在单击按钮时调用 post api,但显示此错误:

提供的参数与调用目标的任何签名都不匹配

代码:

changeStatus(id) {
    this.http.post('https://localhost:44300/api/apis/ChangeStatus/' + id)
        .subscribe(
            data => this._data = data.json(),
            err => this.logError(err)
        );
}

【问题讨论】:

  • 错误出现在哪一行?
  • 第二行代码this.http.post('https://localhost:44300/api/apis/ChangeStatus/' + id)

标签: typescript angular


【解决方案1】:

http.post 期望将正文发送到目标主机。

http.post(url, body, requestOptions)

因此,如果您只想要一个空正文,因为您没有额外的数据要发送,您可以这样做:

changeStatus(id) {
    // mind the empty string here as a second parameter
    this.http.post('https://localhost:44300/api/apis/ChangeStatus/' + id, "") 
        .subscribe(
            data => this._data = data.json(),
            err => this.logError(err)
        );
}

【讨论】:

    【解决方案2】:

    post 方法至少需要两个参数,第一个是“URL”,第二个是“Body”,在您的代码中,您只是传递 URL 而不是正文。

    【讨论】:

      猜你喜欢
      • 2017-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-26
      • 2017-10-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多