我有用於從後端獲取購物車數據的此購物車組件。從angular2 * ngFor數組獲取特定值
import { Component, OnInit } from '@angular/core';
import { CartService } from './cart.service';
@Component({
selector: 'cart',
templateUrl: './cart.component.html',
styleUrls: ['./cart.component.css']
})
export class CartComponent implements OnInit{
carts: any;
cartItems: any;
totalPrice: Number;
constructor(private _cartService: CartService){};
ngOnInit(){
this.getItems();
}
getItems(){
this._cartService.getCartItems(localStorage.getItem('currentUserId'))
.subscribe((cart) => {
this.cartItems = cart.products;
this.totalPrice = cart.totalPrice;
this.carts = cart;
console.log(this.carts)
},
(err) => console.log(err));
}
}
這是我的對象值。
我把所有的內部cartItems產品我的組件,並使用循環在我的模板* ngFor
<tbody *ngFor="let cartItem of cartItems">
在如圖所示這是結果
現在我想更新一個項目的數量,按下刪除按鈕旁邊的刷新按鈕,然後它會發送j在產品詳細信息中,我已將刷新按鈕按下到我的後端。
有人可以幫助我如何使它發生?
什麼是不工作? –
我需要從數組中獲取對象值。例如產品Fast,我會將數量更新爲10,我如何從* ngFor數組中獲取? –