1

So far I've only found examples that put the objects in the rows (1)(2)(3), but I need to put the objects in the columns and their attributes in the rows.

Example of JSON:

[
  {
    name: 'peanut butter',
    price: 0.99
  }
  {
    name: 'strawberry jelly',
    price: 0.99
  }
  {
    name: 'white bread',
    price: 2.99
  }
]

Example of desired table:

table that shows a row for name and a row for price, with peanut butter, strawberry jelly and white bread and their prices in the columns

2
  • 1
    I guess you need to first check for all available attributes you got, and create a list based of this. Then do an ng-repeat on this list for the table-rows. Inside this do a second ng-repeat for the objects in the columns. <tr ng-repeat="attr in attributes"><td>{{attr.name}}</td><td ng-repeat="obj in objList"></td></tr> - if you don't need a dynamic version, do like Konrad suggested in his answer, with a hardcoded list of rows. Commented Dec 19, 2016 at 13:54
  • I'll try that when I need to build a reusable directive. Thanks for the tip! Commented Dec 19, 2016 at 14:39

1 Answer 1

1

I think you want something like this.

Angular template:

<table>
  <tr>
    <th>Name</th>
    <th ng-repeat="item in yourList">{{ item.name }}</th> 
  </tr>
  <tr>
    <td>Price</td>
    <td ng-repeat="item in yourList">{{ item.price }}</td> 
  </tr>
</table>
Sign up to request clarification or add additional context in comments.

Comments

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.