在我的 angular2 模板中访问嵌套对象时出现问题。错误:
Error: Uncaught (in promise): Error: Error in /app/admin/property/items/property-items.html:7:52 caused by: self.context.property.PropertyDataType is undefined
我的模板代码:
<div class="col-xs-12 content-area" *ngIf="property.PropertyDataType.IsList == true">
</div>
但是当我在组件中使用 console.log(object) 时,我可以访问所有属性。看截图:
我本来以为我可以通过模板中的“property.PropertyDataType.IsList”访问嵌套属性,但它似乎无法识别嵌套属性:PropertyDataType。
任何帮助将不胜感激。谢谢
最佳答案
如果 Angular 解析绑定(bind)时尚未设置值,您可以使用安全导航运算符来防止错误:
*ngIf="property?.PropertyDataType?.IsList == true"
关于angular - 访问 angular2 模板中的嵌套属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41892225/