在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5  HTML/ Cannot read property 'XXX' of undefined

Cannot read property 'XXX' of undefined

angular2里,在ts中取出后臺封裝的對象數(shù)組([Object,Object...]),在html中,直接引用對象的屬性(Object.XXX)就會報錯“Cannot read property 'XXX' of undefined”,但是頁面又已經(jīng)顯示出了XXX。但是用ngFor遍歷出對象集合,再引用其中一個對象的XXX屬性,就不會報錯。這怎么解決呢

顯示但報錯:

      {{questions[currentNo].content}}

正常:

      <ng-container *ngFor="let qsn of questions ;index as qNo" >
        <div class="qsnHost" *ngIf="qNo==currentNo">
          {{qsn.content}}
        </div>
      </ng-container>
     
回答
編輯回答
陌上花

{{qsn?.content}}

<div *ngIf="qsn">
<div class="qsnHost" *ngIf="qNo==currentNo">

  {{qsn.content}}

</div>
</div>

2018年4月14日 18:39