ng-repeat 执行多次 [英] ng-repeat execute many times
本文介绍了ng-repeat 执行多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个关于 jsfiddle 的小演示 :
I have a little demo on jsfiddle :
HTML:
<input type="checkbox" id="chkUsr{{usr.Id}}" ng-model="usr.Checked">
{{usr.Name}} : {{usr.Checked}}
<input type="text" ng-model="research"/>
<div ng-repeat="entity in entities | filter:research | log">
Hello {{entity.id}}!
JavaScript:
JavaScript:
app.filter('log', function() {
return function(items) {
console.log('yo');
return items;
};
});
当输入改变时调用日志过滤器(即使是复选框).
The log filter is called when input change (even the checkbox).
如何更改并仅在文本输入更改时触发日志过滤器?
How to change that and trigger log filter only when text input change ?
推荐答案
那是因为 angular 运行 $digest
并更新所有作用域属性,即使作用域中的一个变量发生变化.它被称为脏检查".
That's because angular runs $digest
and updates all the scope properties even if one variable in the scope changes. It is called "dirty checking".
了解有关 angular 工作原理的更多信息:http://www.sitepoint.com/理解角度应用摘要/
Learn more about how angular works: http://www.sitepoint.com/understanding-angulars-apply-digest/
这篇关于ng-repeat 执行多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文