1

When using the controllerAs syntax in AngularJS, the controller is added into the scope.

But is it excluded when dirty checking is performed ?

Potentialy, something changed in the controller but has no effect on the view, and nothing needs to be updated.

If the controller is not ignored by dirty checking it can trigger unnecessary updates, how does angular prevents this to happen ?

dou bret
  • 267
  • 2
  • 11
  • _"something changed in the controller but has no effect on the view ... it can trigger unnecessary updates"_ That's a contradiction. If it has no effect then it doesn't trigger updates. – a better oliver Feb 16 '17 at 12:35
  • a controller can hold a reference to a service, and something can change in the service but not in the controller. If the controller participates to the dirty checking then the service also participates (because of the reference in the controller). – dou bret Feb 16 '17 at 12:39
  • 1
    Dirty checking is done by watchers. If you don't create a watcher checking the service you mentioned then the service will never be involved in dirty checking. Angular doesn't check the service just because it's referenced by the controller. And again: Having no effect on the view means no updates. That's the definition of no effect. – a better oliver Feb 16 '17 at 12:58
  • @zeroflagL is right, updates are triggered because of watchers, when it has a watcher it means that some update will trigger when dirty checking detect changes, on your views, watchers are created automatically by angularjs directives and interpolations (i.e., `{{ $ctrl.myProp }}`). Also, changes has nothing to do with the effect on view but by the watchers that is created by your code. If you have a directive that create a watcher to change an element class when a property gets changed or a controller that watch some property to register a log will both require an update when changes happen. – lenilsondc Feb 16 '17 at 13:15
  • I think I understand. Angular creates watchers on a per binding basis, right ? The controllerAs syntax does not create a watcher even if the controller is stored in the scope ? – dou bret Feb 16 '17 at 13:48

0 Answers0