Dmitry Dmitry - 11 days ago 6
AngularJS Question

Filling the table in a loop

How to fill a table in the loop?
I have an array of values, and I want to automatically fill in the table.

<table>
<thead>
<tr>
<div ng-repeat="n in range" >
<th> {{vm.data.list[n].temp.day}} {{vm.symbal}}
{{vm.data.list[n].humidity}} %
</th>
<div>
</tr>
</thead>
</tr>
</table>


And script:

var range = [];
for(var i=0;i<7;i++) {
range.push(i);
}
$scope.range = range;

Answer

you do not need to create a range array, just iterate your list:

<table>
  <tr>
    <th>Day temp</th>
    <th>Symbal</th>
    <th>Humidity</th>
  </tr>
  <tr ng-repeat="item in vm.data.list">
    <td ng-bind="item.temp.day"></td>
    <td ng-bind="vm.symbal"></td>
    <td ng-bind-template="{{ item.humidity }} %"></td>
  </tr>
</table>

plunker: http://plnkr.co/edit/PeTrMWJIBjXLegOQ1wRx?p=preview