I'm receiving a list of cart items from a service subscription and I want to take each CartItem object in that list and use one of its fields as a parameter for another service call ... which returns its own list, a list of products. Here's the code representation:
cartItems: CartItem[];
products: Product[];
fetchCartItems() {
this.cartService.getCartItemsList().subscribe(
cartItems => {
this.cartItems = cartItems
for (let cartItem of this.cartItems) {
// find the product with the cartItem's product_id
this.productService.getProduct(cartItem.product.id).subscribe(
product => { this.products.push(product); }
);
}
}
);
}
Is there a better way of doing this?