I have a function that creates an array of Observables (batchOfRequests) from an array of items (myItemsArray). Each myItem pushes one Observable (http request) with two parameters from properties of myItem (propertyOne, propertyTwo, etc.) I then use Observable.concat to make the requests for each Observable in the batchOfRequests. This works fine and I can see the data returned from each request in returnedData. However, at this point, I have no idea which myItem in the myItemsArray belongs to each request. Is there a way to link or map each myItem to the Observable that was pushed into the batchOfRequests ?
performMultipleRequests(): void
{
let batchOfRequests: Observable<any>[] = [];
for (let myItem of this.myItemsArray)
{
this.batchOfTrendRequests.push(this.myService.makeHTTPCall(myItem.propertyOne, myItem.propertyTwo))
}
this.batchOfRequests = this.batchOfRequests.map(obs =>
{
return obs.catch(err => Observable.of(err));
});
Observable.concat(...this.batchOfRequests)
.finally(() =>
{
return;
})
.subscribe((returnedData: any) =>
{
// do something with my returned data... but I need myItem information as well
return;
}), (error) =>
{
return;
}
}