我正在动态地绑定下拉下拉键,在这里我无法显示默认标签选择的值,而且如果我更改了选择,则该值也不显示在标签中。
以下是我的代码
<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);
}
应该如下,
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);
}