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
the problem here is that your this.getItem()
method isn't returning an Observable
, instead it returns AngularFireObject
, which hasn't pipe
property, so you should call valuChanges
method which will return an Observable
private getItem(cartId: string, productId: string){
return this.db.object('/shopping-carts/' + cartId + '/items/' + productId).valueChanges();
}
async addToCart(product: Product){
let cartId = await this.getOrCreateCartId();
let item$ = this.getItem(cartId, product.key);
item$.pipe(take(1)).subscribe(item => {
item$.update({ product: product, quantity:(item.quantity || 0) + 1 });
});
}