0

I have a dictionary where the value is itself an object. I want to show the entries in a table using ng-repeat.

Here is the dictionary:

{
        'adam': {
            c1: "a",
            c2: "b"
        },
        'amalie': {
            c1: "c",
            c2: "d"
        }
    };

I have visited this question but it talks about simple key-value pairs.

Here is a jsfiddle.

I want it to be shown as:

NAME c1 c2
adam a b
amalie c d
Community
  • 1
  • 1
vishalaksh
  • 2,054
  • 5
  • 27
  • 45

4 Answers4

1
<ul>
    <li ng-repeat="(name, ages) in items">              
        {{name}} 
        <span ng-repeat="age in ages">
            {{age}}
        </span>        
    </li>
</ul>

jsfiddle

Yangguang
  • 1,785
  • 9
  • 10
0
<div ng-app ng-controller="MyCtrl">
    <ul>
        <li ng-repeat="(name, age) in items">{{name}}: {{age.c1}} : {{age.c2}}</li>
    </ul>
</div>

use like this...

Gnanadurai A
  • 278
  • 1
  • 2
  • 15
0

Check this updated jsFiddle. Hope this helps.

<div ng-app ng-controller="MyCtrl">
    <table>
        <tr>
            <td>Name</td>
            <td>C1</td>
            <td>C2</td>
        </tr>

        <tr ng-repeat="(name, age) in items">
            <td>{{name}}</td>
            <td>{{age.c1}}</td>
            <td>{{age.c2}}</td>
        </tr>

    </table>
</div>

http://jsfiddle.net/5dh0d8nd/2/

Shai Aharoni
  • 1,955
  • 13
  • 25
0

It can be like this:

<div ng-app ng-controller="MyCtrl">
    <table style="width:50%">
         <tr>
            <th>NAME</th>
            <th>C1</th>
            <th>C2</th>
         </tr>   
         <tr ng-repeat="(name,age) in items">
            <td>{{name}} </td>
            <td> {{age.c1}}</td>        
            <td> {{age.c2}}</td>
         </tr>
   </table>
</div>
<table style="width:100%">

</table>

See this Fiddle.

Aurelio
  • 24,702
  • 9
  • 60
  • 63
Ved
  • 11,837
  • 5
  • 42
  • 60