I am making an http call that returns an observable of a list of products. For each product I need to subscribe to an observable which contains the price (since it is a separate request from another service).
I think this is working, but not sure if this is how it should be done:
return this.httpService.get(url, config).pipe(map(res => res.data.map(product => {
let price;
this.productPriceService.getPriceByProductId(product.id).subscribe(value => price = value);
return {
id: product.id,
name: product.name,
price
}
})));
I have also tried the following an I am getting a circular JSON reference error:
return this.httpService.get(url, config).pipe(map(res => res.data.map(product => {
return {
id: product.id,
name: product.name,
price: this.productApiService.getPriceByProductId(product.id).subscribe(value => price = value)
}
})));