我正在尝试打印我的回复,但出现错误:
[ts]
Argument of type 'HttpEvent<any>' is not assignable to parameter of type 'string'.
Type 'HttpSentEvent' is not assignable to type 'string'.
(parameter) res: HttpEvent<any>
执行此操作的代码块是:
post(endpoint: string, body: any, reqOpts?: any) {
let observable = this.http.post<any>(this.url + '/' + endpoint, body, reqOpts).share();
observable.subscribe(res => {
this.core.log(res);
}, err => {
this.core.log(err);
this.core.toast("server err " + err);
});
return observable;
}
答案 0 :(得分:1)
我理解您的问题是这样的:您发出一个http请求,并希望打印该请求的响应?!
为此:
post(endpoint: string, body: any, reqOpts?: any) {
this.http.post(this.url + '/' + endpoint, body, reqOpts).subscribe(res => {
this.core.log(res); //here you can return the result
//return result
}, err => {
this.core.log(err);
this.core.toast("server err " + err);
});
}