AngularJS: Can you get a 'digest in progress' error from multiple
$scope.$apply() calls?
In a large application where you might have a large scope, if you call
$scope.$apply multiple times in rapid succession, can you get a 'scope
already in progress' error?
E.g, I have a directive which is linked to the bootstrap switch plugin.
This directive simply shows an on/off switch which the user can click to
toggle a boolean value as true/false. Each time the user clicks this
button, my directive does a $scope.$apply() in which one scope variable is
changed to reflect the new state of the switch (on or off).
I was worried that if a user clicks the switch in rapid succession, I
might get the 'digest already in progress' error. However, that isn't the
case, each time things go very smoothly and the scope value is updated
everywhere instantly despite multiple $scope.$apply() calls being fired.
Is this because $scope.$apply is optimized somehow so it doesn't run a
full digest, but only updates those values which were changed, or is it
just because my scope is relatively small at the moment so the full digest
isn't taking long to be run?
No comments:
Post a Comment