I have JSON Array object as shown below.
$scope.items =
[
{Name: "Soap", Price: "25", Quantity: "10"},
{Name: "Bag", Price: "100", Quantity: "15"},
{Name: "Pen", Price: "15", Quantity: "13"}
];
I want to get the keys and values separately using ng-repeat in angular.js. I have tried the following code but its not working.
<tr ng-repeat="(key, val) in items">
<td>{{key}}</td>
<td>{{val}}</td>
</tr>
I believe the problem is with the braces '[' and ']'. Can anyone please suggest me how the issue can be resolved ?
Edited:
Thank you so much for the reply. I have tried your code and its working. But my real requirement is display the items as shown below.
Name Price Quantity
Soap 25 10
Bag 100 15
Pen 15 13
I am using some <tr>
and <td>
in html. But nothing getting displayd in screen. The codes are shown below.
<table>
<tr ng-repeat="item in items">
<tr ng-repeat="(key, val) in item">
<td>{{key}}</td>
<td>{{val}}</td>
</tr>
</tr>
</table>
I know that <tr>
inside of another <tr>
is not permitted by html. I tried by best.But no luck.
It will be great if you could help me in this.
Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…