Problem description: I would like to retrieve array of products from server. For this I have a function that does the following:
getProducts(customerId): Observable<Product[]> {
this.http.get(
'http://<url>'+'?productId='+productId)
.map((responseData) => {
return responseData.json();
})
.map((products: Array<any>) => {
let result:Array<Product> = [];
if (products) {
products.forEach((product) => {
result.push(
new Product(product.id,
product.mediaId,
product.description,
product.name));
});
}
return result;
}
My question is the following: I want to retrieve the image for each product that needs to be shown along with the product name and description. In order to retrieve the image I need to call another http endpoint on the server and pass product.mediaId as the parameter. So what I am not clear about is how do I do this. Do I need to make one more http.get call for each product retrieved by the previous http.get call. What is the RxJS observable and functional way of doing this? It would be great if someone could shed some light on this issue.