I have an http service which returns an object array, and by using this results am calling another service as given in the example. Now how can I combine the intermediate and final results at the end. For eg: result1Data[0] + result2Data[0] etc..
var result1= this.service1.getData();
result1.pipe(
switchMap(data => {
let result2 = data.map(result1Data => {
return this.service2.getData(result1Data);
});
return forkJoin(...result2);
})
).subscribe(result2Data => {
//combine result1Data and result2Data
})
Here's how it could be implemented:
var result1 = this.service1.getData();
result1.pipe(
switchMap(result1Data => {
return forkJoin(result1Data.map(this.service2.getData))
.pipe(
map(result2Data => {
//combine result1Data and result2Data ()
})
)
)
})
).subscribe(result3 => {
// allready combined
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With