0

I have my json data coming from DB , however column names may be different by different project and I need to show it in table using angularjs, How Can I iterate over the json data using ng-repeat using another ng-repeat for keys.

For example

data = {
    "id": 2,
    "project": "wewe2012",
    "date": "2013-02-26",
    "description": "ewew",
    "eet_no": "ewew",
}

now while rendering , I don't know the keys which comes in json data but I can pass array of keys like

keys = ['id','project','date','description']

Now I want to use each key from keys and render on HTML, Please help

I have tried something like this, but did not help.

<tr ng-repeat='item in data'>
  <span ng-repeat =  key in keys>
     <div>{{ item.key }}</div>
Boaz
  • 19,892
  • 8
  • 62
  • 70
  • 1
    Possible duplicate of [How to use ng-repeat for dictionaries in AngularJs?](http://stackoverflow.com/questions/11985863/how-to-use-ng-repeat-for-dictionaries-in-angularjs) – Boaz Oct 16 '15 at 22:06

2 Answers2

0

Try this:

<tr ng-repeat='item in data'>
    <span ng-repeat="key in item">
       <div>{{ item[key] }}</div>
mr100
  • 4,340
  • 2
  • 26
  • 38
0

You could generate table header like this:

<!-- table header -->
<tr>
    <th ng-repeat="(key, value) in data">{{key}}</th>
</tr>
Michel
  • 26,600
  • 6
  • 64
  • 69