RXJS 6处理http Observable的方式是什么?

rob*_*más 2 javascript rxjs typescript angular

我注意到当我在新项目中使用它时,我的代码不起作用:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

import { TypeAndCountURL } from '@app/constants';
import { HttpErrorService } from '@app/services/http-error.service';
import { TypeAndCountResponseBody, TypeAndCountRequestBody } from '@app/models/type-and-count/bodies.interface';

@Injectable({
  providedIn: 'root'
})
export class ApiService {
  constructor (private http: HttpClient, private httpErrorService: HttpErrorService) {}

  postTypeAndCountRequest(typeAndCountRequestBody: TypeAndCountRequestBody): Observable<TypeAndCountResponseBody> {
    return this.http.post<TypeAndCountResponseBody>(TypeAndCountURL, typeAndCountRequestBody).pipe(
      catchError(this.httpErrorService.handleError<TypeAndCountResponseBody>('postTypeAndCountRequest'))
    );

  }
}
Run Code Online (Sandbox Code Playgroud)

具体来说,我正在 Cannot find name 'catchError'. Did you mean 'RTCError'?ts(2552)

仔细阅读,我可以通过单独导入来解决问题(从rxjs / operators .. whihc很好,但是)..而且整个结构都是rxjs 5的兼容模式...什么是RXJS 6处理错误响应的方式?

Ton*_*Ngo 5

尝试像这样导入

import { catchError } from "rxjs/operators";
Run Code Online (Sandbox Code Playgroud)

更新也许是这样的吗?

fetchUser() {
   this.userService.getProfile()
      .subscribe(
         (data: User) => this.userProfile = { ...data }
          , // success path
          error => this.error = error // error path
   );
}
Run Code Online (Sandbox Code Playgroud)