typescript - Angular 2错误提供的参数与调用目标的任何签名都不匹配

标签 typescript angular

我试图在点击按钮时调用 post api 但我显示了这个错误:

Supplied parameters do not match any signature of call target

代码:

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

最佳答案

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

http.post(url, body, requestOptions)

所以如果你只是想要一个空的 body ,因为你没有额外的数据要发送,你可以这样做:

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)
        );
}

关于typescript - Angular 2错误提供的参数与调用目标的任何签名都不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38324447/

相关文章:

reactjs - Typesafe React 装饰器无法识别传递函数的 ReturnType

angular - 从 Mapbox 弹出窗口重定向到 Angular 分量

angular - 在 Angular Interceptors 中获取当前路线

angular - 如何按照 "action hygiene"指南使用多个 NGRX 操作来执行相同的操作?

Angular 2 : How to have the same guard for multiple components

Angular 5 Material Table 用具有不同参数类型的函数替换 filterPredicate

angular - 将数据从一个组件传递给服务,然后再传递给另一个组件

php - Angular 4 - 如何使用参数将数据获取到数据库

typescript - TypeScript 中的内部模块和外部模块有什么区别?

angular - 有没有办法在 Angular 7 中使用模板 html 属性 *key* 的变量?