【问题标题】:ERROR TypeError: Cannot read property 'nom_gr' of null ?? on Chrome错误类型错误:无法读取 null 的属性“nom_gr”??在 Chrome 上
【发布时间】: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 &amp;&amp; slide.nom_gr" 而不是*ngIf="slide.nom_gr != null || slide.nom_gr ==' ' "

标签: javascript html angular ionic2


【解决方案1】:

在处理异步绑定时,您应该使用安全导航? 运算符。

所以替换

slide.nom_gr

slide?.nom_gr

【讨论】:

  • 他再次告诉我 nom_gr 为空,但在 mozilla 上 nom_gr 存在
猜你喜欢
  • 2021-12-03
  • 2017-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-05
  • 2017-12-15
  • 1970-01-01
相关资源
最近更新 更多