Reputation: 1396
I want to display a select list whereby the first value in my ngFor array is selected.
My code is:
<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>
I would like to know how to place checked="true"
such that it is only for the first value of the ngFor loop.
Note: I am using a old version of Ionic 2 (2.0.0-beta.4
) so the syntax is different from current versions which uses selected="true"
. But would appreciate any suggestions!
Upvotes: 1
Views: 331
Reputation: 2218
You can make use of ngModel
instead of checked="true"
.
In your .js:
this.account = this.userAccountData[0].name;
Basically this works the same way as checked
.
Upvotes: 1