模板/在angular2空数组渲染属性? [英] Templating/rendering properties in an empty array in angular2?

查看:217
本文介绍了模板/在angular2空数组渲染属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://jsfiddle.net/48yh14c3/

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

在角1,你可以参考深属性和(在大多数情况下)将继续摇摆:

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>

我敢肯定,我可以只* ngIf parent属性,以确保它的存在,或压平原来的POJO。只是想知道如果我失去了一些东西?

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?

推荐答案

是的,你缺少的 Elvis操作符

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

<大骨节病> Plunker

这篇关于模板/在angular2空数组渲染属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆