How does AngularJS $watch these cases in an ng-repeat?

后端 未结 1 467
自闭症患者
自闭症患者 2020-12-03 18:44

I understand that AngularJS sets up some watches on ng-repeat. What type of watch is setup at this point?

Also, can someone explain what happens in each of these sc

相关标签:
1条回答
  • 2020-12-03 19:12

    Each ng-repeat will set up a $watch on items. (If you look at the ng-repeat source code, most of it is the watchExpression function of the $watch method). Each time an Angular digest cycle runs, each item in items will be examined by this watch function. (Note that in a digest cycle, this watch function could be called more than once).

    Each {{}} sets up a $watch. If something like item.property is inside the {{}}s, it is dirty checked at least once per digest cycle.

    If a function is inside {{}}s, then that function is called at least once per digest cycle.

    I'm not sure about x | filter, but this fiddle seems to indicated that the filter is called at least once every digest cycle, even if x doesn't change.

    0 讨论(0)
提交回复
热议问题