基于Angular 2

时间:2016-09-18 14:03:58

标签: angular

我有以下内容:

<ion-slides>
  <ion-slide *ngFor="let item of items | async" >
    <button [class.current]="currentItem == item">
      {{ item.whatever}}
    </button>
  </ion-slide>
</ion-slides>

如果current等于item,则只应设置课程currentItem。但是,currentItem也是从数据源(SQLite)异步加载的。因此,首次呈现视图时,currentItem为null。

我需要做什么才能在加载currentItem时让视图等待更新?

1 个答案:

答案 0 :(得分:1)

您应该使用安全导航操作员(?。),如下所示

<ion-slides>
  <ion-slide *ngFor="let item of items | async" >
    <button [class.current]="currentItem?.id == item.id">  //<----here
      {{ item.whatever}}
    </button>
  </ion-slide>
</ion-slides>
相关问题