ng-repeat执行多次 [英] ng-repeat execute many times

查看:209
本文介绍了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 ?

推荐答案

这是因为角度运行 $ 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".

了解有关角度如何工作的更多信息: http://www.sitepoint.com/understanding-angulars-apply-digest/

Learn more about how angular works: http://www.sitepoint.com/understanding-angulars-apply-digest/

这篇关于ng-repeat执行多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆