1

As we all know AngularJS uses the simplest form of $watch when we bind to variable in template like this {{ $ctrl.obj }}.
It should compare value of $ctrl.obj by reference, but if I mutate $ctrl.obj the change is reflected in view. The reference doesn't changed, so why?

lealceldeiro
  • 14,342
  • 6
  • 49
  • 80
  • See my latest answer. Your last comment made me realize my previous answer was wrong. BTW, according to the [source code](https://github.com/angular/angular.js/blob/master/src/ng/directive/ngBind.js#L62), the `ngBind` directive do not use the third parameter: the relevant part is: `scope.$watch(attr.ngBind, function ngBindWatchAction(value) { element.textContent = stringify(value); });` – lealceldeiro Sep 21 '18 at 16:06

1 Answers1

0

When we use brackets ({{}}) angular does not use any watch (ers) for detecting changes on the expression placed inside them. Instead this expression is dirty checked and refreshed in every $digest cycle, even if it is not necessary.

See this post: AngularJS : Why ng-bind is better than {{}} in angular?

lealceldeiro
  • 14,342
  • 6
  • 49
  • 80