也许这是一个愚蠢的问题。读了几遍这个https://angular.io/docs/ts/latest/guide/template-syntax.html我找不到解决方案来引用对象数组中的对象。
我尝试过这个
{{ users[0] ? users[0].description }}
我得到了这个
Parser Error: Conditional expression {{ users[0] ? users[0].description }} requires all 3 expressions at the end of the expression [ {{ users[0] ? users[0].description }} ] in
我尝试过这个
{{ users.0 ? users.0.description }}
我得到了这个
Unexpected token '0' at column 7 in [ {{ users.0 ? users.0.description }} ]
以上任何语法都是正确的,而我的错误在其他地方,或者以上都不正确。对不起我的英语
代码中的某处
..//
users: Array<Object>;
..//
this.users = new Array();
..//
this.users.push(users.json())
..//
最佳答案
您必须提供三元运算符的“else”部分。所以只需将其更改为:
{{ 用户[0] ?用户[0].description : '' }}
关于angular - 在模板内的 Angular 2 中引用对象数组中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35446546/