0

How do I access an object attribute based on a variable in an Angular template? I have an object that has an attribute based on a user selection, so how do I tell the Angular template to get that value? For example, the user chooses q26 and I access the object like this:

{{ item.q26 }}

it woks no problem. But if a user chooses q28, it obviously wouldn't work. I can successfully pass the value the user chooses to the template but how do I get Angular to read that variable as an object attribute. I know this doesn't work but the idea would be:

{{ item }}.{{ user_selection }}

Thanks!

2
  • 1
    {{ item[user_selection] }} just like with objects. Commented Jun 17, 2015 at 17:03
  • It would be helpful if you could share your code on JSFiddle or Plunker. Commented Jun 17, 2015 at 17:03

0

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.