0

I'm using ng-repeat through a list of objects that consist of displayNames and variables. For example, here is an example fields list:

"fields": [
    {"displayName": "Company Name", "variable": "name"},
    {"displayName": "Location of Product", "variable": "location"},
]

Currently I'm doing something like this:

<div ng-repeat="field in fields">
    <label class="control-label">{{field.displayName}}</label>
    model.{{field.variable}}
</div>

I want model.{{field.variable}} to display the value of the model.variable value. So for example, if field.displayName is "Company Name", then I want to display model.name.

I tried wrapping it all in curly braces {{model.{{field.variable}}}} but it didn't work.

Thanks!

0

1 Answer 1

4

You need to use the bracket notation when you have a dynamic key.

<div ng-repeat="field in fields">
    <label class="control-label">{{ field.displayName }}</label>
    {{ model[field.variable] }}
</div>
Sign up to request clarification or add additional context in comments.

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.