У меня есть *ngFor
, и я пытаюсь обновить метку {{subtotal}}
по щелчку, но он обновляет все элементы с одинаковым значением. То же самое и с {{quantity}}
. Есть ли способ создать локальные переменные? Вот мой код
HTML
<CardView class="cardStyle" *ngFor="let card of shoppingCart; let i = index;">
<Label text="{{card?.product.productName}}" textWrap="false" class="product-title " row="1" col="0"></Label>
<Label text="Quantity:{{quantity}}" textWrap="true" col="1" row="2" class="product-quantia" ></Label>
<Label text="subtotal:{{subtotal}}" textWrap="true" col="1" row="2" class="product-quantia" ></Label>
<Button text="" class="item-share-shop-save" (tap)="increase(card, i)" ></Button>
</CardView>
мой компонент ТС
subtotalResult:any = null;
quantity: any;
increase(card:any, id:number){
card.quantity += 1;
this.subtotalResult = card.quantity * card.unitPrice;
}