How to catch exception correctly from http.request()?

Perhaps you can try adding this in your imports: import ‘rxjs/add/operator/catch’; You can also do: return this.http.request(request) .map(res => res.json()) .subscribe( data => console.log(data), err => console.log(err), () => console.log(‘yay’) ); Per comments: EXCEPTION: TypeError: Observable_1.Observable.throw is not a function Similarly, for that, you can use: import ‘rxjs/add/observable/throw’;

Chaining RxJS Observables from http data in Angular2 with TypeScript

For your use case, I think that the flatMap operator is what you need: this.userData.getUserPhotos(‘123456’).flatMap(data => { this.userPhotos = data; return this.userData.getUserInfo(); }).subscribe(data => { this.userInfo = data; }); This way, you will execute the second request once the first one is received. The flatMap operator is particularly useful when you want to use the … Read more

Angular/RxJS When should I unsubscribe from `Subscription`

TL;DR For this question there are two kinds of Observables – finite value and infinite value. http Observables produce finite (1) values and something like a DOM event listener Observable produces infinite values. If you manually call subscribe (not using async pipe), then unsubscribe from infinite Observables. Don’t worry about finite ones, RxJs will take … Read more

How do I return the response from an Observable/http/async call in angular?

Reason: The reason that it’s undefined is that you are making an asynchronous operation. Meaning it’ll take some time to complete the getEventList method (depending mostly on your network speed). So lets look at the http call. this.es.getEventList() After you actually make (“fire”) your http request with subscribe you will be waiting for the response. … Read more