Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

javascript - ng-repeat execute many times

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...