Does AngularJS reuse observers?
<div ng-repeat="item in items">
{{ item.name }}
</div>
<div ng-repeat="item in items">
{{ item.name }} - {{ item.number}}
</div>
In this example, AnglerJS reuses observers for items
, item
and item.name
or does it register new observers even though they are actually "physically" the same object or property?
source to share
He will register new observers. However, if you have reason to know that these values will not change after setting them, you can help communicate this to AngularJS with a new option in 1.3.x (I think 1.3.14 and up):
<div ng-repeat="item in items">
{{ :: item.name }}
</div>
This will create a short-lived observer that waits until item.name is "lowered" (becomes the real value and does not change for a single digest). After that, you will no longer have an observer. This is great for things like message lists that won't change unless you activate it yourself by adding / removing elements.
source to share