Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-repeat in nested array in AngularJS

I am having a problem. I have an array.

myArray = [{ 
 "John": [{"salary":"15K","year":"2013"},{"salary":"20K","year":"2014"}]
},{
 "Ben": [{"salary":"17K","year":"2013"},{"salary":"20K","year":"2014"},{"salary":"25K","year":"2014"}]
 }];

I want it to display in a table.The array can have much more data. Please someone, tell me If I am arranging the array wrong or something. I am stuck in this for sometime now.

like image 976
Bikash Ramtel Avatar asked Mar 13 '23 15:03

Bikash Ramtel


1 Answers

It will be great if you specified the format of the table. If you want a table like table-heads as name and values. In names we can show the name and inside values there is another table of salary and year. For such a table you can follow steps as given below.

<table>
  <tr>
    <th>Name</th>
    <th>Values</th>
  </tr>
  <tr ng-repeat="person in myArray">
    <td>{{person.name}}</td>
    <td>
      <table>
        <tr>
          <th>Salary</th>
          <th>Year</th>
        </tr>
        <tr ng-repeat="each in person">
          <td>{{each.salary}}<td>
          <td>{{each.year}}<td>
        </tr>
      </table>
    </td>
  </tr>
</table>
like image 91
Syam Pillai Avatar answered Mar 24 '23 18:03

Syam Pillai