ng-repeat execute many times

2020-02-06 17:32发布

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:

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 ?

1条回答
聊天终结者
2楼-- · 2020-02-06 18:05

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".

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

查看更多
登录 后发表回答