我将项目升级到 ionic 4 和 Angular 7,并修复了代码中的所有导入和错误,以使其根据 Angular 7 的更改工作。
唯一认为我无法使用HttpClient
解决以下问题:
if (params.method == 'GET') {
return this.http.get(url, {headers: headers, params: request_params, withCredentials: true})
.timeout(10000)
.pipe(catchError(this.errorHandler()));
}
我收到两个错误,第一个是:
Property 'timeout' does not exist on type 'Observable'.ts(2339)
还有:
Cannot find name 'catchError'. Did you mean 'RTCError'?ts(2552)
this.errorHandler()
是在出现问题时发送错误。
最佳答案
通过使用 Angular 7,您正在使用 RxJS 6+,您已经完成了一些迁移,但您忘记将 timeout
放入 pipe
中。
另外,如果您想将函数传递给catchError
,只需传递它而不调用它(不带括号)
if (params.method == 'GET') {
return this.http.get(url, {headers: headers, params: request_params, withCredentials: true})
.pipe(
timeout(10000),
catchError(this.errorHandler)
);
}
关于angular - 在 get 请求中找不到 Ionic 4 和 Angular 7 超时和 catchError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54764129/