【发布时间】:2018-12-12 21:34:11
【问题描述】:
<ion-col col-9 class="sildes">
<ion-slides slidesPerView="{{nbPerPage}}" spaceBetween="5">
<ion-slide *ngFor="let slide of lesEboxs; let i = index" (click)="saveCurrentSlide(i)">
<button *ngIf="slide.nom_gr != null || slide.nom_gr ==' ' " ion-button block [style.background-color]="(slide === this.slideClicked) ? '#DFF2FF' : '#B8D3DE'" (click)="this.slideClicked = slide"
(click)="ecardGroup(slide)" class="currentGroup">
<ion-icon class="warning" name="star" *ngIf="slide.nom_gr == 'Pro'"></ion-icon>
{{slide.nom_gr}}
</button>
</ion-slide>
</ion-slides>
</ion-col>
使用 mozilla 没有问题,但使用 chrome 却让我出错:ERROR TypeError: Cannot read property 'nom_gr' of null
我检查了 web 服务返回给我的内容,结果中没有 null,所以我不明白错误来自哪里
有人可以帮我吗?谢谢
【问题讨论】:
-
可能是一个 asyc 问题,其中
slide在呈现模板时为空。试试安全导航运算符。 -
使用
*ngIf="slide && slide.nom_gr"而不是*ngIf="slide.nom_gr != null || slide.nom_gr ==' ' "
标签: javascript html angular ionic2