Property 'catch' does not exist on type 'Observable'

后端 未结 3 822
無奈伤痛
無奈伤痛 2020-12-02 07:20

On the Angular 2 documentation page for using the Http service, there is an example.

getHeroes (): Observable {
  return this.http.get(this.ur         


        
3条回答
  •  再見小時候
    2020-12-02 07:55

    In angular 8:
    for catch:
    import { catchError } from 'rxjs/operators';
    
    for throw:
    import { Observable, throwError } from 'rxjs';
    
    and code should be written like this.
    
    getEmployees(): Observable {
        return this.http.get(this.url).pipe(catchError(this.erroHandler));
      }
    
      erroHandler(error: HttpErrorResponse) {
        return throwError(error.message || 'server Error');
      }
    

提交回复
热议问题