更新时间:2023-11-26 16:02:22
是的,您缺少 猫王运算符:
{{thing.property[0]?.anotherProp}}
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?
Yes, you're missing the Elvis operator:
<div *ngFor='#thing of list'>
{{thing.property[0]?.anotherProp}}
</div>