我是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>
答案 0 :(得分:1)
您可以将[(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;
}
答案 1 :(得分:0)
您需要在while final_answer_check == True:
try:
final_answer = str(input("Do you want a copy of the answers?"))
if final_answer.lower() == "no":
final_answer_check = False
方法中使用<p *ngFor="let o of options">
<label *ngIf="o.letter === selectedOption">Countries are: {{ o.countries }}<label>
</p>
传递选定的值,如下所示
component.ts
$event.target.value
component.html
firstDropDownChanged()
希望这会有所帮助!
答案 2 :(得分:0)
在TS中尝试
this.currentPrice = this._values1.map((value: number) => {
return parseInt(this.product.subtotal) * value
});
然后在HTML中的“选择”下方添加
(change)="firstDropDownChanged($event.target.value)"
答案 3 :(得分:0)
您可以尝试这样,希望对您有帮助
TS
currentPrice: number = 0;
private _values1 = [" 1 ", "2", " 3 "," 4 "," 5 "," 6 "];
firstDropDownChanged(data: any)
{
this.currentPrice = +this.product.subtotal * +data.target.value;
console.log(this.currentPrice);
this.product.subtotal = this.currentPrice;
}
HTML
<select class="sel" (change)="firstDropDownChanged($event)">
<option *ngFor='let v of _values1'>{{ v }}</option>
</select>
让我知道它是否正常运行