3

I have an array of arrays (representing rows and columns) and I need to render an HTML table with the data.

Each row is an array of column values, for example: $scope.table.row[0] = [123, 456, 789]

This is my attempt (that doesn't work). Any ideas?

<table>
    <tbody>
        <tr ng-repeat="row in table">
            <td ng-repeat="col in row">{{col}}</td>
        </tr>    
    </tbody>
</table>
4
  • 1
    Post the entire data Commented Jul 28, 2016 at 10:52
  • 1
    $scope.table.row[0] = [123, 456, 789]; $scope.table.row[1] = [111, 222, 333]; $scope.table.row[2] = [444, 555, 777] Commented Jul 28, 2016 at 10:52
  • 1
    $table vs table Commented Jul 28, 2016 at 10:53
  • 1
    Then you need either <tr ng-repeat="row in table.row"> or ` table[0] = [123, 456, 789]; table[1] = [111, 222, 333]; table[2] = [444, 555, 777]` Commented Jul 28, 2016 at 10:57

2 Answers 2

6

You either need to iterate over table.row or make table an array of arrays itself. Demo.

<table>
    <tbody>
        <tr ng-repeat="row in table.row">
            <td ng-repeat="col in row">{{col}}</td>
        </tr>    
    </tbody>
</table>

OR

table = [ [123, 456, 789], [111, 222, 333], [111, 222, 333]]

<table>
    <tbody>
        <tr ng-repeat="row in table">
            <td ng-repeat="col in row">{{col}}</td>
        </tr>    
    </tbody>
</table>
Sign up to request clarification or add additional context in comments.

Comments

1

Also you can use *ngFor like this:

rows = [['a1','a2', 'a3'],['b1','b2', 'b3'],['c1','c2', 'c3']]'
<table>
  <tbody>
    <tr *ngFor="let row of rows">
      <td *ngFor="let item of row">
        {{ item }}
      </td>
    </tr>
  </tbody>
</table>

result:

a1 a2 a3
b1 b2 b3
c1 c2 c3

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.