我是ionic 3的新手,想了解代码,请帮帮我。
我想选择任何项目,它的值get的更改小计可能反映了它的输出。

购物车

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路数据绑定

<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

09-25 18:28