访问angular2模板中的嵌套属性

时间:2017-01-27 10:51:46

标签: angular angular2-template

在我的angular2模板中访问嵌套对象时遇到问题。错误:

  

错误:未捕获(在承诺中):错误:/app/admin/property/items/property-items.html:7:52错误导致:self.context.property.PropertyDataType未定义

我的模板代码:

    <div class="col-xs-12 content-area" *ngIf="property.PropertyDataType.IsList == true">
    </div>

但是当我在我的组件中使用console.log(object)时,我可以访问所有属性。见截图:

enter image description here

我想我可以通过&#34; property.PropertyDataType.IsList&#34;来访问嵌套属性。在我的模板中,它似乎没有识别嵌套属性:PropertyDataType。

任何帮助都会感激不尽。谢谢

1 个答案:

答案 0 :(得分:4)

当Angular解析绑定时,您可以使用安全导航操作符来防止错误:

*ngIf="property?.PropertyDataType?.IsList == true"
相关问题