I want to to get data for several different ProductIds from an remote source using httpClient within an angular service. I want to combine the data within the service and then return it.
Using just one productId, this works just fine:
getData(productId: string): Observable<any> {
const path = this.serverUrl + '?' + 'productId=' + productId;
return this.httpClient.get(path);
}
But how can I iterate over an array of product Ids and then return the combined result?
getData(productIds: Array<string>): Observable<any> {
let data: Array<string>;
productIds.forEach(element => {
const path = this.serverUrl + '?' + 'productid=' + element;
data.push(this.httpClient.get(path));
});
return data;
}
Thanks for your help!