【问题标题】:Ionic select, preselected value with options loop离子选择,带有选项循环的预选值
【发布时间】:2021-06-29 09:53:26
【问题描述】:
我正在尝试使用预选值和生成的选项创建离子选择,但我面临问题,在与选择交互之前不会显示初始选择。我假设这个组件正在检查基于给定值显示的可用选项,然后在 *ngFor 循环中生成选项。我做错了吗?或者有什么办法可以解决这个问题?
<ion-select value="preselect.id">
<ion-select-option *ngFor="let item of itemList" [value]="item.id">
{{ item.name}}
</ion-select-option>
</ion-select>
【问题讨论】:
标签:
javascript
angular
ionic-framework
ion-select
【解决方案1】:
我通过添加 ngModel 解决了同样的问题。
<ion-select (click)="loadcurrency()" [(ngModel)]="selectedcurrency">
<ion-select-option *ngFor="let currency of currencies"
value="{{currency.name}}">{{currency.capital}}
</ion-select-option>
</ion-select>
在 .ts 文件中
selectedcurrency = "aud";
loadcurrency() {
....//initialize the array for options
}