$timeout / $apply / $digest in modern Angular
There is no digest cycle. Updating a signal tells Angular what changed, wherever the update comes from.
Before · AngularJS
$timeout(function () { vm.saved = false; }, 2000);
socket.on('message', function (msg) {
$scope.$apply(function () { vm.messages.push(msg); });
});After · AngularsetTimeout(() => this.saved.set(false), 2000);
socket.on('message', msg => {
this.messages.update(list => [...list, msg]);
});What changes
- $timeout and $interval become setTimeout, setInterval or RxJS timer.
- $scope.$apply is not needed: signal updates work from any callback.
- The '$digest already in progress' error disappears with the digest cycle.
Migration tip. In a hybrid app, changes made by Angular code may still need to reach AngularJS watchers. Keep that bridging in one shared service, not scattered through components.
Related
- ng-transclude
- $httpProvider.interceptors
- form validation (ng-required, $error)
- $stateChangeStart / transition hooks
Planning a migration or a micro-frontend platform?
In a 20-minute call you describe your situation and I tell you how I'd approach it. If it isn't worth doing yet, I'll say so.
Message me on LinkedIn