angular 中自己常用的下拉框获取值方法

方法一

HTML页中

<select name="" id="if02" data-first-option="true" (change)="getChange($event.target.value)">
  <option value="-1">--请选择--</option>
  <option [value]="true">是</option>
  <option [value]="false">否</option>
</select>
 
ts中
getChange(val: number) {
  console.log(val);
  if(val==1){
    this.currentRow.condition01 = "true";
    }else if(val==0){
    this.currentRow.condition01 = "false";
  }
}
 
方法二
html中
<select class="btn btn-outline-primary" name="if03" id="if03" [(ngModel)]="currentRow.condition03" style="height: 40px;;width: 130px">
  <option [ngValue]="1">是</option>
  <option [ngValue]="0">否</option>
</select>
其中
currentRow.condition03 是数据源的一个字段 实际上是和数据库的某个字段绑定
 
不理解数据源的话可以
在ts中定义一个变量   然后[(ngModel)]="定义的变量"   即可
 
 
 

猜你喜欢

转载自www.cnblogs.com/Samuel-Leung/p/9382593.html
今日推荐