Angular – Make multiple HTTP calls sequentially

This can be achieved using the switchMap operator. This example uses RxJS 5.5+ pipeable operators. import { switchMap } from ‘rxjs/operators’; registerUser(user: User) { return this.utility.getIpAddress().pipe( switchMap(data => { this.ipAddress = data.ip; const body = { UserName: user.UserName, Email: user.Email, UserIP: this.ipAddress, }; return this.http.post(this.registerAPI, body); }) ) } RxJS < 5.5: import { switchMap … Read more

Is it good to call subscribe inside subscribe?

The correct way is to compose the various observables in some manner then subscribe to the overall flow — how you compose them will depend on your exact requirements. If you can do them all in parallel: forkJoin( this.service.service1(), this.service.service2(), this.service.service3() ).subscribe((res) => { this.funcA(res[0], res[1], res[2]); }); If each depends on the result of … Read more

Leveraging the observer pattern in JavaFX GUI design

As noted here, the JavaFX architecture tends to favor binding GUI elements via classes that implement the Observable interface. Toward this end, Irina Fedortsova has adapted the original Converter to JavaFX in Chapter 5 of JavaFX for Swing Developers: Implementing a Swing Application in JavaFX. I’ve recapitulated the program below, updating to Java 8 and … Read more

Angular 7 – nesting Observables

We can make use of pipeable RxJS operators for this scenario. First, we can use RxJS’s mergeMap to map over the observable values from route into an inner observable. If params and params[‘client_name’] are defined, we assign params[‘client_name’] to the client_name property, which is similar to your initial code. Then, we call the getClientDetails() method … Read more

How to make one Observable sequence wait for another to complete before emitting?

A couple ways I can think of import {take, publish} from ‘rxjs/operators’ import {concat} from ‘rxjs’ //Method one var one = someObservable.pipe(take(1)); var two = someOtherObservable.pipe(take(1)); concat(one, two).subscribe(function() {/*do something */}); //Method two, if they need to be separate for some reason var one = someObservable.pipe(take(1)); var two = someOtherObservable.pipe(take(1), publish()); two.subscribe(function(){/*do something */}); one.subscribe(function(){/*do … Read more

Rxjs One Observable Feeding into Another

For transforming items emitted by an Observable into another Observable, you probably want to use the flatMap operator. It creates an inner Observable and flats its result to the outer stream. const source = this.myService .getFoo() .pipe( flatMap(result => this.myService.getMoo(result)) ) .subscribe(result2 => { // do some stuff }); Here are some flat operators you … Read more

Is it a good practice using Observable with async/await?

Chaining Observables in sequence, as you want to do in your code Concerning your code example, if you want to chain Observables (trigger another after the previous emits), use flatMap (or switchMap) for this purpose : this.serviceA.get() .flatMap((res1: any) => this.serviceB.get()) .flatMap((res2: any) => this.serviceC.get()) .subscribe( (res3: any) => { …. }); This one is … Read more

RxJS Observables nested subscriptions?

As mentioned in comments, you are looking for the flatMap operator. You can find more details in previous answers : How to do the chain sequence in rxjs Why do we need to use flatMap? Your example would read as : this.returnsObservable1(…) .flatMap(success => this.returnsObservable2(…)) .flatMap(success => this.returnsObservable3(…)) .subscribe(success => {(…)});