I'm new in rxjs and after readed tons of articles I feel a bit confused. I have a lot of nested http requests,that fetch data from the API. First request gets the list of my devices, every device contains a list of sensors, every sensor contains a list of temperatures. The first API request returns the devices list with sensors array filled, but the temperatures array are empty. At this point I must do one http request for each sensors to fetch temperatures data.
I tried to use switchmap combined with forkJoin, but in the observable subscription I obtain only the arrays of temperatures. How can I fill temperatures arrays of each sensor?
APIconnector.GetDevices()
.pipe(
tap(devices => {console.log(devices)}),
switchMap(devices => forkJoin(devices.map(device => device.Sensors))),
tap(sensors => {console.log(sensors)}),
switchMap(sensors => forkJoin(sensors.map(sensor => {
const param = {
MinutesInterval: 30,
StartDate: stDate,
EndDate: new Date(),
SensorIds: [sensor.Id]
};
return APIconnector.GetIntervalRange(param);
})))
).subscribe(data => {
console.log(data);
})
I need all the data returned by the API, not only the last one.
-- UPDATE --
I hope this stackblitz sketch can help you.