我目前正在研究Angular 8应用程序。我想相对于购物车中的物品数量增加购物车中的总金额。但是目前正在发生的事情是,当我增加数量时,购物车中的价格保持不变。 任何帮助将不胜感激。 谢谢!
我的HTML代码
<div class="modal-footer padding-10">
<a href="javascript:void(0);" (click)="addToCart(filteredRecipe,'isExtra')"
class="btn-second btn-submit">Add to Cart
<span *ngIf="recipeTotal!=0">{{recipeTotal | currency :'GBP':'symbol':'1.2-2'}}</span>
</a>
</div>
<div class="u-line">
<div class="product-quantity padding-10"><span class="text-light-black fw-700 fs-16">Quantity</span>
<div class="input-group quantity">
<div class="input-group-append">
<button (click)="quantityControl('-')" class="minus-btn" type="button" name="button">
<i class="fas fa-minus"></i>
</button>
</div>
<input type="text" class="text-center" [(ngModel)]="quantity" name="quantity" value="1" style="font-size: 18px; font-weight: bold;">
<div class="input-group-prepend">
<button (click)="quantityControl('+')" class="plus-btn" type="button" name="button"><i
class="fas fa-plus"></i>
</button>
</div>
</div>
</div>
</div>
我的TS代码
quantityControl(flag) {
if (flag == '+') {
this.quantity = this.quantity + 1;
if (this.filteredRecipe.RecipePrice != null) {
this.recipeTotal = this.recipeTotal + this.filteredRecipe.RecipePrice;
}
} else {
if (this.quantity != 1) {
this.quantity = this.quantity - 1;
if (this.filteredRecipe.RecipePrice != null) {
this.recipeTotal = this.recipeTotal - this.filteredRecipe.RecipePrice;
}
}
}
}