Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  8] [ 7]  / answers: 1 / hits: 120902  / 8 Years ago, fri, may 6, 2016, 12:00:00

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



getHeroes (): Observable<Stuff[]> {
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.


More From » angular

 Answers
3

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:




[#62281] Wednesday, May 4, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emmaleet

Total Points: 203
Total Questions: 107
Total Answers: 98

Location: Cook Islands
Member since Thu, May 21, 2020
4 Years ago
emmaleet questions
Wed, Apr 28, 21, 00:00, 3 Years ago
Thu, Jan 7, 21, 00:00, 3 Years ago
Sat, Nov 28, 20, 00:00, 4 Years ago
Sat, Apr 18, 20, 00:00, 4 Years ago
;