我想显示一个选择列表,其中选择 ngFor 数组中的第一个值。
我的代码是:
<ion-select [(ngModel)]="account" (change)="changeAccount(account)">
<ion-option *ngFor="#userAccount of userAccountData" value="{{ userAccount.name}}">{{ userAccount.name}}</ion-option>
<ion-option value="new" checked="false">New Account</ion-option>
</ion-select>
我想知道如何放置checked="true"
这样它仅适用于 ngFor 循环的第一个值。
注意:我使用的是旧版本的 Ionic 2 ( 2.0.0-beta.4
),因此语法与使用 selected="true"
的当前版本不同。 。但如果有任何建议,我们将不胜感激!
最佳答案
您可以使用ngModel
代替checked="true"
。
在你的 .js 中:
this.account = this.userAccountData[0].name;
基本上,这与 checked
的工作方式相同。
关于javascript - Ionic 2 - 将 ngFor 中的第一个值选择为 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43970479/