Reputation: 21658
Maybe this is a stupid question. After reading several times this https://angular.io/docs/ts/latest/guide/template-syntax.html I can not find a solution, to reference an object within an array of objects.
I tried it with this
{{ users[0] ? users[0].description }}
I obtain this
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
I tried it with this
{{ users.0 ? users.0.description }}
I obtain this
Unexpected token '0' at column 7 in [ {{ users.0 ? users.0.description }} ]
any of the above syntax is correct and my mistake is elsewhere, or none of the above is correct. Sorry for my English
somewhere in code
..//
users: Array<Object>;
..//
this.users = new Array();
..//
this.users.push(users.json())
..//
Upvotes: 2
Views: 1619
Reputation: 657148
You were probably looking for
{{ users[0]?.description }}
Upvotes: 2
Reputation: 1198
You have to provide the "else" part of the ternary operator. So just change it to:
{{ users[0] ? users[0].description : '' }}
Upvotes: 3