If you declare the keys of the objects you are executing, you can nest your ng-repeats so that you do not need to declare each line again and again. Do the following and nest them instead:
In an Angular app:
var personKeys = ['firstName', 'LastName', 'EmailID', 'ContactNo']; var people = [ { firstName: 'Bob', LastName: 'Doe', EmailID: ' bob@xyz.com ', ContactNo: 123123 }, ]; this.pKeys = personKeys; this.people = people;
In your HTML:
<table ng-controller='MyController as personList'> <tr ng-repeat='key in personList.pKeys'> <th>{{key}}</th> <td ng-repeat='person in personList.people'> {{person[key]}} </td> </tr> </table>
This problem still has a problem with iteration of each person | attributes | times, not just once. I'm sure there is a smart way to just repeat once, memoize and compose a table without going through the entire data set many times, so that the runtime does not grow as fast as you expand your data.
source share