Templating/rendering properties in an empty array in angular2?

我是研究僧i 提交于 2019-12-12 04:17:02

问题


http://jsfiddle.net/48yh14c3/

this.list = [
 {
  property: [{anotherProp: true}]
 },
 {
  property: []
 },
 {
  property: [{anotherProp: false}]
 }
]

In angular 1 you could reference deep properties and (for the most part) it would keep on rocking:

<div ng-repeat='thing in ctrl.list'>
   {{thing.property[0].anotherProp}}
</div>

I'm sure I could just *ngIf the parent property to make sure it exists, or flatten the original POJO. Just wondering if I'm missing something?


回答1:


Yes, you're missing the Elvis operator:

<div *ngFor='#thing of list'>
   {{thing.property[0]?.anotherProp}}
</div>

Plunker



来源:https://stackoverflow.com/questions/34340950/templating-rendering-properties-in-an-empty-array-in-angular2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!