que1326 que1326 - 24 days ago 6
AngularJS Question

How to use ng-repeat by table data?

Given this array of 7 elements (7 arrays with 1 element each) I want to display 1 table row (because I have 1 element in each array) containing 7 table data. So the table output should be something like this:

some label1 | some label2 | some label3 | some label4 | some label5 some label6 | some label7
0


JavaScript

$scope.array = [
[
{
id: 1,
label: 'some label1'
}
],
[
{
id: 2,
label: 'some label2'
}
],
[
{
id: 3,
label: 'some label3'
}
],
[
{
id: 4,
label: 'some label4'
}
],
[
{
id: 5,
label: 'some label5'
}
],
[
{
id: 6,
label: 'some label6'
}
],
[
{
id: 7,
label: 'some label7'
}
]
];


HTML

<table>
<tr ng-repeat="item in array"></tr> // this will generate 7 rows
</table>

Answer

You can do the following:

<table>
  <tr>
    <td ng-repeat="item in array">{{item[0].label}}</td>
  </tr>
</table>

And here is a working sample: https://plnkr.co/edit/sYo6YPuMmZ3B9EGhznkS?p=preview

Comments