patternjavascriptangularCritical
Property 'catch' does not exist on type 'Observable<any>'
Viewed 0 times
propertyexistobservableanydoesnotcatchtype
Problem
On the Angular 2 documentation page for using the Http service, there is an example.
I cloned the angular2-webpack-starter project and added the above code myself.
I imported
I'm assuming the properties
getHeroes (): Observable {
return this.http.get(this.url)
.map(this.extractData)
.catch(this.handleError);
}I cloned the angular2-webpack-starter project and added the above code myself.
I imported
Observable using import {Observable} from 'rxjs/Observable';I'm assuming the properties
Observable are imported as well (.map works). Looked at the changelog for rxjs.beta-6 and nothing is mentioned about catch.Solution
Warning: This solution is deprecated since Angular 5.5, please refer to Trent's answer below
=====================
Yes, you need to import the operator:
Or import
But in this case, you import all operators.
See this question for more details:
=====================
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]
Code Snippets
import 'rxjs/add/operator/catch';import {Observable} from 'rxjs/Rx';Context
Stack Overflow Q#37073705, score: 253
Revisions (0)
No revisions yet.