angularjs 使用 ng-repeat 两次调用过滤器 [英] angularjs calling Filter twice with ng-repeat
问题描述
我是 angularjs
的新手并试图学习过滤器的概念.但在我的情况下 angularjs
调用过滤器两次.我希望过滤器只运行一次,但它运行了两次.不明白为什么会这样..
I am new to angularjs
and trying to learn concept of filters.But in my case angularjs
is calling the filter twice.I was expecting filter to run only once but its running twice. Cant understand why this is happening..
这是我的plunker...
here is my plunker...
推荐答案
如果我没有把你的问题弄错,这和 这里
Angularjs 使用脏检查"方法,因此它需要调用所有过滤器以查看是否存在任何更改.在此之后,它检测到一个变量(您键入的那个)发生了变化,然后再次执行所有过滤器以检测是否有其他变化.
Angularjs uses a 'dirty-check' approach, so it need to call all the filters to see if exists any change. After this it detect that have a change on one variable(the one that you typed) and then it execute all filters again to detect if has other changes.
为了更清晰的理解,stackoverflow这个问题将由angularjs专家进行更详细的解释
To be more clear understanding, stackoverflow this question will explain in more detail by expert in angularjs
第一次调用来自检测到变化的观察者.因为有一个,所以需要再次调用它们以查看是否有消息更改,因为观察者可以进行更改.
The first call is from the watchers that are detecting the change. Because there is one then they need to be called again to see if is there news changes because a watcher can make changes.
这篇关于angularjs 使用 ng-repeat 两次调用过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!