Answer the question
In order to leave comments, you need to log in
How to return data or make two more requests in Rx.js depending on the result of the first request?
I need to make a request via HttpClient (Angular) After the response comes, I need to return the data if the email does not exist in the database, and if it does, then transfer the stream to two more requests and return the already processed result of these two requests to the subscript callback (Observables since httpClient I use).
Answer the question
In order to leave comments, you need to log in
This is done via switchMap:
this.httpClient.get('/check-email').pipe(
switchMap(emailResult => {
if (emailResult !== exists) {
return of(dataForNonExistingEmail);
}
return forkJoin(
this.httpClient.get('/user-data1'),
this.httpClient.get('/user-data2')
);
})
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question