Reputation: 769
I want to set selected but I tried this below it's not work How to set selected ngfor ionic2 I tried
<ion-item>
<ion-label>Source</ion-label>
<ion-select [(ngModel)]="filter" >
<ion-option value={{item.val}} *ngFor="let item of options" selected="item.val == 'pencil'">{{item.name}}</ion-option>
</ion-select>
</ion-item>
it's not work ,not show selected this to default
ts
public options = [
{
"name": "Pencils",
"val" : "pencil"
}
.
.
.
];
Upvotes: 2
Views: 3974
Reputation: 37373
[selected]
instead of selected
and [value]
instead of value
:
<ion-option [value]="item.val" *ngFor="let item of options" [selected]="item.val == 'pencil'">{{item.name}}</ion-option>
</ion-select>
note :
property
when bind to static value ex: value="someValue"
[property]
when bind to a variable or expression ex: [value]="getSomeValue()"
.Upvotes: 0
Reputation: 191749
Since you have ngModel
, you should set the filter to the selected item initially:
public filter = this.options[0].val;
Upvotes: 2