1

I am attempting to create a table in AngularJS which has multiple rows per item. The output needs to be similar to:

<table>
    <tr><td>Item 1 Row a</td></tr>
    <tr><td>Item 1 Row b</td></tr>
    <tr><td>Item 1 Row c</td></tr>
    <tr><td>Item 1 Row d</td></tr>
    <tr><td>Item 2 Row a</td></tr>
    <tr><td>Item 2 Row b</td></tr>
    <tr><td>Item 2 Row c</td></tr>
    <tr><td>Item 2 Row d</td></tr>
</table>

What would be the best way of achieving this? Is there an approach I can take that requires markup like this:

<table>
    <tag ng-repeat="item in data">
        <tr><td>Item {{item.id}} Row a</td></tr>
        <tr><td>Item {{item.id}} Row b</td></tr>
        <tr><td>Item {{item.id}} Row c</td></tr>
        <tr><td>Item {{item.id}} Row d</td></tr>
    </tag>
</table>

EDIT: data will be along these lines:

{"data": [
     {
         "id": 1
     },
     {
         "id": 2
     },
     {
         "id": 3
     }
 ]}
5
  • what about another ng-repeat? <td ng-repeat="x in ['a','b','c','d']">Item {{item.id}} Row {{x}}</td> Commented Jun 29, 2018 at 10:05
  • Sorry, I've just realised I made a typo in the second code block there. Each <td> should have been in a different row. Editing it now Commented Jun 29, 2018 at 10:14
  • What's in data? Commented Jun 29, 2018 at 10:25
  • Its is an array of json object. Have edited the question to demonstrate Commented Jun 29, 2018 at 10:34
  • can you clear more with your code or output you need? Commented Jun 29, 2018 at 10:35

1 Answer 1

3

Replace the tag with tbody like this:

<table>
    <tbody ng-repeat="item in data">
        <tr><td>Item {{item.id}} Row a</td></tr>
        <tr><td>Item {{item.id}} Row b</td></tr>
        <tr><td>Item {{item.id}} Row c</td></tr>
        <tr><td>Item {{item.id}} Row d</td></tr>
    </tbody>
</table>

This will work.

Your table will have multiple tbody tags if that isn't an issue.

Sign up to request clarification or add additional context in comments.

1 Comment

Thats perfect! Thank you

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.