I have inherited some AngularJS code, and I know very little about it (the code and Angular both). The code that I inherited contains several places where $scope.$digest
is called within a $scope.$on
method within a controller. For example:
$scope.$on("ScriptEditorEnabled", function (e, enabled) {
$scope.scriptEditorDisabled = !enabled;
$scope.$digest();
});
In my context, this is causing the popular $digest
already in progress error (AngularJS : Prevent error $digest already in progress when calling $scope.$apply()). Isn't an $on
method part of the $scope
object, and thus, any changes to its data would be picked up automatically? If so, doesn't that mean that calling $digest
within one (either directly or indirectly), just plain incorrect?
I've been simply removing these calls, seemingly without any loss in functionality, and the errors go away. Is there any dangers I should be aware of when doing this?