我在研究角8的应用程序。我希望将按钮按下的次数乘以现有值(recipetotal)。但它没有给我正确的结果。
结果应该是=> 8*3=24,但我得到的结果是=> 48
有人能帮我解决这个问题吗。
我的TS代码
quantityControl(flag) {
if (flag == '+') {
this.quantity = this.quantity + 1;
if (this.filteredRecipe.RecipePrice === 0) {
this.recipeTotal = this.recipeTotal * this.quantity;
console.log('The price is:'+ this.recipeTotal);
}
} else {
if (this.quantity != 1) {
this.quantity = this.quantity - 1;
if (this.filteredRecipe.RecipePrice === 0) {
this.recipeTotal = this.recipeTotal * this.quantity;
}
}
}
}我的HTML代码
<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>发布于 2020-09-14 15:48:33
可能是这个函数评估的错误。
if (this.filteredRecipe.RecipePrice === 0)通过它代码或自己检查它。
https://stackoverflow.com/questions/63887506
复制相似问题