I\'m a beginner to Angular. I\'m watching the tutorial of Mosh Hamedani using the Angular version 6 but the problem is the tutorial version is 4. I\'m working on the e-comme
maybe instead of changing this line to
return this.db.object('/shopping-carts/' + cartId + '/items/' + productId).valueChanges();
leave it as it was
return this.db.object('/shopping-carts/' + cartId + '/items/' + productId)
then in the function you are calling the getItem function before subscribing to it you can add value changes there
should be something like
`private getItem(cartId: string, productId: string){
return this.db.object('/shopping-carts/' + cartId + '/items/' + productId);
}
async addToCart(product: Product){
let cartId = await this.getOrCreateCartId();
let item$ = this.getItem(cartId, product.key).valueChanges();
item$.pipe(take(1)).subscribe(item => {
item$.update({ product: product, quantity:(item.quantity || 0) + 1 });
});
}`