在我的角度应用程序中,我显示了一个项目列表,我直接从我的数据库加载。我一直在努力让至少20个项目显示出来。用户可以过滤它们,所以当应用太多过滤器时,我想加载更多。
到目前为止,我这样做的方式如下: HTML:
<section id="list" class="ease">
<article class='myItems' ng-repeat="job in filteredList = (items | filter: country | filter: category | filter: position)">
Items
</article>
</section>
JS (在我的控制器中):
$scope.$watch('filteredList', function(newVal, oldVal){
if(newVal !== oldVal){
$log.info($scope.filteredList.length);
// code to load more data
}
});
但是,我得到了以下错误:
Error: 10 $digest() iterations reached. Aborting
我猜这是因为filteredList变化了太多次了,所以角度阻碍了它。我怎么才能解决这个问题?
谢谢
发布于 2014-03-21 12:32:58
使用$scope.$watchCollection
而不是$scope.$watch
,因为filteredList
是一个集合。
使用$scope.$watch
实际上失败了,因为您重新构建了每个消解循环上的引用,因此观察者再次循环和循环,并达到摘要限制。
关于观看方法的有趣文章
https://stackoverflow.com/questions/22558603
复制相似问题