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

Delegation: EventEmitter or Observable in Angular

Update 2016-06-27: instead of using Observables, use either a BehaviorSubject, as recommended by @Abdulrahman in a comment, or a ReplaySubject, as recommended by @Jason Goemaat in a comment A Subject is both an Observable (so we can subscribe() to it) and an Observer (so we can call next() on it to emit a new value). … 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

tech