Property 'pipe' does not exist on type 'AngularFireObject<{}>'

后端 未结 6 1534
一生所求
一生所求 2021-01-03 17:00

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

6条回答
  •  [愿得一人]
    2021-01-03 17:20

    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 });
            });
        }`
    

提交回复
热议问题