With the traditional observable/subscribe pattern I am trying to get a list of clients, with each of those clients get a list of their accounts with client.id
Here's what that looks like:
this.httpService.getClients().subscribe(clients => {
clients.forEach(client => {
this.httpService.getClientAccount(client.id).subscribe(accounts => {
console.log(accounts);
});
});
});
Now I'm trying to do this with mergeMap. I do not think I'm doing it correctly as when I pass in client.id to the second call it is showing as undefined.
this.httpService.getClients().pipe(
mergeMap(client => this.httpService.getClientAccount(client.id))
).subscribe(result => console.log(result))
Can anyone point out what I'm doing wrong here? I tried using tap() to console log the client inside mergeMap but nothing showed up. I'm not sure how to reference the response from the first getClients() call.