我动态绑定下拉列表,在这里我无法显示默认标签选择的值,如果我更改了标签中也没有显示该值的选择。
以下是我的代码
<p>{{locName}}</p>
<ion-grid style="background:#fafafa">
<ion-row>
<ion-col col-6 hidden>
<!--<ion-label>Location</ion-label>-->
<ion-select #sectionSelect [(ngModel)]="location" (ngModelChange)="optionsFn()" hidden>
<ion-option *ngFor="let opt of allowedData" [value]="opt.LocationId">{{opt.LocationName}}</ion-option>
</ion-select>
</ion-col>
</ion-row>
</ion-grid>
locName 中的我必须显示所选数据
下面是我的打字稿代码
optionsFn(){
this.dataone = location;
this.locName = this.dataone.LocationName;
console.log(this.locName);
}
答案 0 :(得分:1)
应该如下,
optionsFn(){
this.dataone = this.location;
this.locName = this.dataone.LocationName;
console.log(this.locName);
}
或将ngModel值传递给函数 用HTML格式
(ngModelChange)="optionsFn(location)"
和TS
optionsFn(value:any){
this.dataone = value;
this.locName = this.dataone.LocationName;
console.log(this.locName);
}