如何选择任何数量及其价值得到改变?

时间:2019-03-26 05:37:47

标签: javascript html angular typescript ionic-framework

我是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>

4 个答案:

答案 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;
  }

Stackblitz Demo using ngModel

答案 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()

Here is stackblitz link

希望这会有所帮助!

答案 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>

让我知道它是否正常运行