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
<ul>
<li ng-repeat="(name, ages) in items">
{{name}}
<span ng-repeat="age in ages">
{{age}}
</span>
</li>
</ul>
<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...
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>
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.