我看到很多与“脏检查”有关的问题。想确认我的下面的问题是由于这一点。AngularJS ng-repeat循环比记录的实际长度长一倍
我有JSON字符串从RestService:基本上两个记录
[{"intRowId":111,"fltAmt":6.0,"intCnt":2,"category":{"intCatId":2,"strCatName":"Rent"},"monthYear":"2016-01-01"},
{"intRowId":112,"fltAmt":3.0,"intCnt":1,"category":{"intCatId":3,"strCatName":"Phone"},"monthYear":"2016-01-01"}]
我已经NG-重复在HTML页面中:我打电话的方法AssignValues。
<tr ng-repeat="op in resultReport">
<td>{{$index+1}}{{resultReport.length}}{{AssignValues(op.fltAmt,$index,op.monthYear)}}</td>
<td>{{op.fltAmt|currency}}</td>
<td>{{op.intCnt}}</td>
<td>{{op.category.strCatName}}</td>
<td>{{op.monthYear}}</td>
</tr>
AssignValues在我的控制器中:打印四次。
$scope.AssignValues = function(amt,ind,mYr){
$log.log(amt);
}
其实我在JSON中有两个记录,但该函数打印出的值比实际长度重复多。它只打印6,3,6,3而不是6和3。屏幕截图如下。任何人都请帮助我理解这一点。
函数必须被调用两次! –
它是由角1x设计的,不要直接从模板调用函数。 – YOU
感谢@NitinVarpe快速回答。我编辑了这个问题。我的意思是,而不是两个记录,它实际上打印4次。 – Shamseer