【问题标题】:Ionic2. ion-option is not checked Visually离子2。 ion-option 未检查 目视
【发布时间】:2016-09-20 05:43:10
【问题描述】:

我在ion-list 中有这个ion-option

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

在我设置的页面/组件内部:

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

视觉上它没有被检查,技术上,它是。:

这些是选项:

看起来它必须是一个数字而不是字符串...... 我该如何解决这个问题?

【问题讨论】:

    标签: data-binding ionic-framework angular ionic2


    【解决方案1】:

    我认为你想要完成的是这样的:

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

    这将显示您的 years 数组中的年份列表,并检查您在 yearModel 中的年份列表(为了清楚起见,我使用了不同的变量名称)。

    例如,如果您在页面文件中使用this.yearModel="2016",它将检查 2016 年。

    【讨论】:

      猜你喜欢
      • 2018-06-27
      • 2017-06-14
      • 2018-12-25
      • 2019-09-02
      • 1970-01-01
      • 2019-07-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      相关资源
      最近更新 更多