angular - 在 get 请求中找不到 Ionic 4 和 Angular 7 超时和 catchError

标签 angular ionic-framework angular7 ionic4

我将项目升级到 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/

相关文章:

angularjs - ionic : Can't scroll up while using anchorScroll in ionic

Angular 7禁用滚动到子路由更改顶部

angular - 我们可以在 angular 7 的 index.html 中添加 <div id ="api"></div> 吗?

typescript - Angular 2 promise 问题

angular - 找不到命名空间 'Microsoft'

Angular2 默认路由 View

angular-material - 无法绑定(bind)到 'errorStateMatcher',因为它不是 'input' 的已知属性

events - Angular2 点击事件未触发

android - 将 AdMob 和 Google-Map 插件与 Ionic 一起使用时出错

leaflet - 实时地理定位 ionic