AngularJS 1.x: $scope vs. $rootscope, $apply() vs. $digest()
What's the different between $scope and $rootScope?
$scope is the current scope.
$rootScope is the global scope - like the scope of global variables in JavaScript.
$rootScope is the parent object of all $scope objects.
How are they initialised?
$scope is created with each controller.
ng-app creates the $rootScope.
Therefore, $rootScope is available to every controller.
What's the different between $apply() and $digest()?
$scope.$digest() triggers a digest cycle on the current scope and its children.
$scope.$apply() calls $rootScope.$digest() is called. Any exceptions are passed to $exceptionHandler, which doesn't happen with $digest().
Therefore $scope.$digest() is faster if you know that you only want to trigger a digest cycle on the current scope.
What's the different between $scope.$apply() and $rootScope.$apply()?
There is no difference between calling $scope.$apply() and $rootScope.$apply() - both will call $rootScope.$digest().
A digest cycle executes all registered $watch listeners, and updates any bindings between the model and view.
When should I call $apply()?
$apply() is already called automatically by directives - Angular automatically manages digest cycles. Only call $apply() manually when needed, e.g. when working with third-party test libraries!