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

后端 未结 3 821
無奈伤痛
無奈伤痛 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:33

    Warning: This solution is deprecated since Angular 5.5, please refer to Trent's answer below

    =====================

    Yes, you need to import the operator:

    import 'rxjs/add/operator/catch';
    

    Or import Observable this way:

    import {Observable} from 'rxjs/Rx';
    

    But in this case, you import all operators.

    See this question for more details:

    • Angular HTTP GET with TypeScript error http.get(...).map is not a function in [null]

提交回复
热议问题