0

I was trying to use ng-repeat to create a table, but I couldn't figure out how to get it to work. My best attempt was the below.

<table ng-repeat="j in [0,1,2,3,4,5,6,7]">
  <tr>
    <th>
      Header {{j+1}}
    </th>
  </tr>
  <tr ng-repeat="i in [0,1,2,3,4,5,6,7]">
    <td>
      {{i+1}} , {{j+1}}
    </td>
  </tr>

</table>

any ideas?

2
  • What is the table structure are you trying to create? Commented Apr 3, 2016 at 17:38
  • do you wanted to create multiple table? and for what j & i stands for. do explain whole context to get help from people.. Commented Apr 3, 2016 at 17:41

1 Answer 1

1

So to begin with, the ng-repeat attribute is on the table, meaning that you are repeating this element as many times as there are entries in your array. Knowing that "tr" stands for the rows, and "td" for different sections in your rows.

You could try:

<table>
  <tr><!--this is your header row -->
    <th>
      Header {{j+1}}<!-- this is a header section, you can repeat here or use it as a title -->
    </th>
  </tr>
  <tr ng-repeat="j in [0,1,2,3,4,5,6,7]"><!-- repeat the rows -->
    <td ng-repeat="i in [0,1,2,3,4,5,6,7]"><!-- repeat the sections -->
      {{i+1}} , {{j+1}}<!-- here you can display i, j whatever else -->
    </td>
  </tr>

</table>
Sign up to request clarification or add additional context in comments.

1 Comment

ok, I needed something with headers showing: so I added <th ng-repeat="j in [0,1,2,3,4,5,6,7]" style="padding = 10px;"> Header {{j+1}} </th>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.