首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按下按钮的次数应与变量(RecipeTotal)值相乘

按下按钮的次数应与变量(RecipeTotal)值相乘
EN

Stack Overflow用户
提问于 2020-09-14 15:37:42
回答 1查看 41关注 0票数 0

我在研究角8的应用程序。我希望将按钮按下的次数乘以现有值(recipetotal)。但它没有给我正确的结果。

结果应该是=> 8*3=24,但我得到的结果是=> 48

有人能帮我解决这个问题吗。

我的TS代码

代码语言:javascript
复制
  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代码

代码语言:javascript
复制
 <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>
EN

回答 1

Stack Overflow用户

发布于 2020-09-14 15:48:33

可能是这个函数评估的错误。

代码语言:javascript
复制
if (this.filteredRecipe.RecipePrice === 0)

通过它代码或自己检查它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63887506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档