javascript - Dynamic variables in HTML and Angular? -


i'm using ng-repeat through list of objects consist of displaynames , variables. example, here example fields list:

"fields": [     {"displayname": "company name", "variable": "name"},     {"displayname": "location of product", "variable": "location"}, ] 

currently i'm doing this:

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

i want model.{{field.variable}} display value of model.variable value. example, if field.displayname "company name", want display model.name.

i tried wrapping in curly braces {{model.{{field.variable}}}} didn't work.

thanks!

you need use bracket notation when have dynamic key.

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

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -