forkJoin: When all observables complete emit the last value from each.
productMap: Map<number, IProduct>
ngOnInit() {
const cart = this.stockService.getCartItems();
const products = this.stockService.getProducts();
Observable.forkJoin(
cart,
products
).subscribe(([cart, products]: [Item[], IProduct[]]) => {
const myMap = products.map<[number, IProduct]>((p) => {
return [p.id, p]; //[0, obj]
});
this.productMap = new Map<number, IProduct>(myMap); // {0: obj}
this.products = products;
cart.forEach((c) => {
this.addStock(c);
})
})
}