2

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())
  ..//
3
  • 1
    Have you tried it like this {{ users[0] ? users[0].description : '' }}? Commented Feb 17, 2016 at 1:59
  • @DonovanM I think it was my mistake because I had parts where used,{{ users[0] ? users[0].description: null}}, but it looks that I forget some, if you want to post a reply? Thanks for your time Commented Feb 17, 2016 at 2:08
  • No problem, just added the answer. Commented Feb 17, 2016 at 2:16

2 Answers 2

3

You have to provide the "else" part of the ternary operator. So just change it to:

{{ users[0] ? users[0].description : '' }}

Sign up to request clarification or add additional context in comments.

Comments

2

You were probably looking for

{{ users[0]?.description }}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.