通过使用API响应,使用ngFor如下创建dom元素。
HTML
<div class="col-sm-2 p-1 eventDiv ripple-container" *ngFor="let actProd of actProdList;let i = index">
<mat-card matRipple class="p-0">
<div class="d-flex justify-content-center mt-2">
<div class="w-100 ProductPrice d-flex justify-content-center">{{actProd?.PRICE}}<span class="pl-1" [innerHtml]="mCurrencyCode"></span></div>
<button type="button" (click)="decrement(actProd?.CODE,i)" class="btnStyles">–</button>
<input type="text" #TotalCartCount readonly class="quantityBox" value="{{mItemCount}}">
<button type="button" (click)="increment(actProd?.CODE,i)" class="btnStyles">+</button>
</div>
</mat-card>
</div>
打字稿
increment(ItemId:number,index:number) {
this.mItemCount += 1;
}
我想做的是,当用户单击“ +”按钮时,我需要更新价格。如何在不刷新dom的情况下实现这一目标。
就您而言,创建两个新属性可能会更好。一种用于产品数量,另一种用于根据价格变化的总价。尝试以下]]
控制器