que1326
que1326

Reputation: 2325

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>

Upvotes: 0

Views: 39

Answers (2)

GPicazo
GPicazo

Reputation: 6676

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

Upvotes: 2

Paul Stoner
Paul Stoner

Reputation: 1512

I would think if you parse the array items and concatenate them into a string then you should be able to do something like this

<table>
  <tr>
    <td ng-bind="scope variable name"/>
  </tr>
</table>

Upvotes: 0

Related Questions