Helpful links for Angular element.$on
, and $scope.$watch
, $digest
,
and $apply
:
- http://docs.angularjs.org/api/angular.element
- http://docs.angularjs.org/api/ng.$rootScope.Scope
- http://www.benlesh.com/2013/08/angularjs-watch-digest-and-apply-oh-my.html
- http://stackoverflow.com/a/15113029/456814
Note: Ben Lesh doesn't recommend using $apply
in a controller, but in a
directive or service instead.
When the browser calls into JavaScript the code executes outside the Angular execution context, which means that Angular is unaware of model modifications. To properly process model modifications the execution has to enter the Angular execution context using the
$apply
method. Only model modifications which execute inside the $apply method will be properly accounted for by Angular.