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

Mal*_*iri 16 typescript angular

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

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

码:

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

rin*_*usu 23

http.post 期望将主体发送到目标主机.

http.post(url, body, requestOptions)
Run Code Online (Sandbox Code Playgroud)

因此,如果您只想要一个空体,因为您没有其他数据要发送,您可以这样做:

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)
        );
}
Run Code Online (Sandbox Code Playgroud)