I am fairly new to Angular. I have some code using ng-repeat.
This is the html:
<div ng-controller="myCtrl">
<h2>Testing ng-repeat and sortable table</h2>
<table>
<tbody ui-sortable ng-model="list">
<tr ng-repeat="item in list" style="cursor: move;">
<td>{{log("ng-repeat on table with sorting:",$index); "index: " + $index + " array-item: " + item}}</td>
</tr>
</tbody>
</table>
<h2>Testing ng-repeat</h2>
<div ng-repeat="item in list">
{{log("ng-repeat on div",$index); "index: " + $index + " array-item: " + item}}
</div>
</div>
This is the controller:
myapp.controller('myCtrl', function ($scope) {
$scope.list = ["a0","a1"];
var count = 0;
$scope.log = function(title,index) {
++count;
console.log(title, "count:", count, "index:", index);
};
});
Plunkr http://plnkr.co/edit/uc7Bd3?p=preview
I was expecting to see 4 lines in the log (console), but there are 12 lines, as you see here:
ng-repeat on table with sorting: count: 1 index: 0
ng-repeat on table with sorting: count: 2 index: 1
ng-repeat on div count: 3 index: 0
ng-repeat on div count: 4 index: 1
ng-repeat on table with sorting: count: 5 index: 0
ng-repeat on table with sorting: count: 6 index: 1
ng-repeat on div count: 7 index: 0
ng-repeat on div count: 8 index: 1
ng-repeat on table with sorting: count: 9 index: 0
ng-repeat on table with sorting: count: 10 index: 1
ng-repeat on div count: 11 index: 0
ng-repeat on div count: 12 index: 1
Why is it not only 4 lines (the number the two ng-repeats are looping through)?