igor
igor

Reputation: 147

Making two http requests sequentially in angular, rxjs

Currently I have the following request:

      return this.registrationService.registratePerson(data).pipe(
        switchMap(
          res => {
            return this.registrationService.sendPassportScan(this.form.value.passportScanCopyFile, res.AisUserIsn);
          }
        )
      );

The second request makes use of the result obtained in the first one, that's something that I need but the problem with it is that now it returns what comes from the second request (the inner one). Is it possible somehow with the help of rxjs operators to make it return an observable containing fields from the inner request as well as those from the outer one?

In the application the 5th version of rxjs is used.

Upvotes: 1

Views: 422

Answers (2)

mbojko
mbojko

Reputation: 14689

Sure. Something like this:

return this.registrationService.registratePerson(data).pipe(
    switchMap(
        res => forkJoin(
            of(res), 
            this.registrationService.sendPassportScan(/* relevant args */),
        )))

(The resulting stream will contain a 2 element array).

Upvotes: 1

Related Questions