【问题标题】:Angular 5+, Http Interceptor Response - Property 'map' does not exist on type 'Observable<HttpEvent<any>>'Angular 5+,Http 拦截器响应-“Observable<HttpEvent<any>>”类型上不存在属性“map”
【发布时间】:2018-11-18 21:53:51
【问题描述】:

如果有人在使用 Http 拦截器时遇到错误,说明:

" 属性 'map' 在类型 'Observable>' 上不存在"。我已经在下面发布了对我有用的解决方案。

我的包裹是:

rxjs - 5.5.6,

@angular/core - 5.2.0,

打字稿 - 2.4.1

【问题讨论】:

  • 当我在 Visual Studio 和 VS Code IDE 中打开项目时,我也会收到此错误,但它不会出现此错误,但无论如何它都不会阻止项目运行

标签: angular5 httpresponse angular-http-interceptors


【解决方案1】:

以下是帮助我在拦截器中捕获响应的解决方案。

return next.handle(request).pipe(
  map((res: HttpResponse<any>) => {
    let body = res.body;
     if(body){
        console.log(“data “, body);
     }
      return res; 
  }),
  catchError((error: any) => {
  console.log(“error “, error);
  return Observable.throw(error);
}));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    • 2018-09-19
    • 2018-10-25
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2023-03-13
    相关资源
    最近更新 更多