javascript - 如何选择任何数量并更改其值?

标签 javascript html angular typescript ionic-framework

我是 ionic 3 的新手,想了解代码请帮助我。 我想选择任何项目,它的值得到的更改小计可能会反射(reflect)到它的输出。

cart.ts

private _values1 = [" 1 ", "2", " 3 "," 4 "," 5 "," 6 "];

  firstDropDownChanged(_values1: any) 
  {
    this.currentPrice = (parseInt(this.product.subtotal) * this._values1);
    console.log(this.currentPrice);
    this.product.subtotal =this.currentPrice;
    console.log(this.product._values1);
  }

cart.html

  <span style="font-size: 14px !important;">Qty:</span>   
  <select class="sel" (change)="firstDropDownChanged()">
  <option *ngFor='let v of _values1'>{{ v }}</option>
  </select>

最佳答案

您可以使用 [(ngModel)] 作为 2 向数据绑定(bind)

<select class="sel" (change)="firstDropDownChanged()" [(ngModel)]="selectedValue">
        <option *ngFor='let v of _values1' [ngValue]="v">{{ v }}</option>
 </select>

因此,每次更改选项时,所选选项的当前值将在 selectedValue 变量中。在 .ts 文件中用作

firstDropDownChanged() {
   this.currentPrice = this.product.subtotal * this.selectedValue;
    console.log(this.currentPrice);
    this.product.subtotal =this.currentPrice;
  }

Stackblitz Demo using ngModel

关于javascript - 如何选择任何数量并更改其值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55350480/

相关文章:

javascript - 在 div 中获取一个 span innerHTML

javascript - 复制到剪贴板在 safari 中不起作用

css - 左侧 Angular 中的 float 工具栏

Angular http.get header 未被识别

javascript - JQuery index() - 哪条路?

javascript - 注释嵌套参数

javascript - ReactJS dropzone 通过 webdriver 上传文件

javascript - 尝试在 android webview 中附加图像

html - 表的标题对齐

c# - 在 Angular 6 中传递带有空字符串的整数值时不调用 API Get 方法