1

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.

2 Answers 2

1

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).

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah that's exactly what I was looking for! And if, say, I want to flatten that array, I can do this in map that I will have to add right after switchMap, right?
Yes, map will do that.
0

concatMap may help you in this case

https://www.learnrxjs.io/operators/transformation/concatmap.html

Example https://angular-academy.com/rxjs-switchmap-concatmap-mergemap-exhaustmap/#concatmap

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.