I recently inherited some AngularJS code, and my knowledge of both the codebase and Angular itself is limited. Within the code I inherited, there are instances where $scope.$digest
is being called inside a $scope.$on
method within a controller. Here's an example:
$scope.$on("ScriptEditorEnabled", function (e, enabled) {
$scope.scriptEditorDisabled = !enabled;
$scope.$digest();
});
This practice has been triggering the common $digest
already in progress error (AngularJS : Prevent error $digest already in progress when calling $scope.$apply()). Since an $on
method is indeed part of the $scope
object, shouldn't any data changes be automatically detected? If that's the case, does it make calling $digest
within one redundant or even incorrect?
In my experience, removing these $digest
calls seems to resolve the issue without impacting functionality. Are there any potential risks associated with this approach that I should be aware of?