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