-1

I have an JSON like following.

{
"PT": {
    "value": "Week 9 Cleaning and Rotation"
},
"PREV_STATUS": {
    "value": "ordered"
}

Where PT and PREV_STATUS etc are ID of fields and values is its values. list of fields and values may changes dyanamically.

i want to show in html so field PT can show value from JSON string.

my HTML is

<div style="font-size: 14px;">{{Object.editedValue.PT.value}}</div>

this line shows a value of PT array i.e. Week 9 Cleaning and Rotation

Is there any way to make field name dyanamic?

somthing like

 <div style="font-size: 14px;">{{Object.editedValue.{{field_NAME}}.value}}</div>

Because field name is dynamically generated.

Mayank Pandya
  • 1,593
  • 2
  • 17
  • 40
  • Use the controller to set the value to a scope variable! – Tobias Nov 09 '15 at 07:27
  • you can iterate through the Keys available using `ng-repeat`, I think you are looking for something like this http://stackoverflow.com/questions/15127834/how-can-i-iterate-over-the-keys-value-in-ng-repeat-in-angular – M22an Nov 09 '15 at 07:28

2 Answers2

0

Just like in JavaScript:

{{ Object.editedValue[field_NAME].value }}
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
0

You can iterate through the Keys available using ng-repeat, I think you are looking for something like this How can I iterate over the keys, value in ng-repeat in angular.

You can basically do something like,

<div ng-repeat="(key, val) in Object.editedValue">
<div style="font-size: 14px;">{{val.value}}</div>
...
</div>
Community
  • 1
  • 1
M22an
  • 1,242
  • 1
  • 18
  • 35