Catalin
Catalin

Reputation: 258

Ionic2. ion-option is not checked Visually

I have this ion-option inside a ion-list:

  <ion-select [(ngModel)]="year">
    <ion-option checked="true">
      {{year}}
    </ion-option>
    <ion-option *ngFor="#year of years">
      {{year}}
    </ion-option>
  </ion-select>

And inside the Page/Component I set:

this.year  = '2016';
this.day = 30;
this.month = 'Jan';

Visually it's not checked, technically, it is.:

enter image description here

These are the options:

enter image description here

As it seems it must be a number not string... How can I solve this?

Upvotes: 0

Views: 75

Answers (1)

Manu Vald&#233;s
Manu Vald&#233;s

Reputation: 2372

I think what you are trying to accomplish is something like this:

  <ion-select [(ngModel)]="yearModel">
      <ion-option *ngFor="#year of years" value="{{year}}">
      {{year}}
    </ion-option>
  </ion-select>

This will show the list of years in your years array, and will check the one you have in yearModel (I used a different variable name for clarity).

For example if you do this.yearModel="2016" in you page file, it will check the year 2016.

Upvotes: 1

Related Questions