How can I effectively use $timeout to delay updates in AngularJS without causing unwanted digest cycles?
Quick question that's been bugging me - After trying multiple solutions online, I still can't figure this out... I'm currently working on an AngularJS application (version 1.8.2) where I need to delay the update of a model variable until a certain time has passed, but I've run into issues with digest cycles. I want to use `$timeout` for this purpose, but it seems to trigger multiple digest cycles unnecessarily. For instance, I have the following code: ```javascript app.controller('MyController', function($scope, $timeout) { $scope.myModel = 'Initial value'; $scope.updateModel = function() { $timeout(function() { $scope.myModel = 'Updated value'; }, 2000); }; }); ``` When I call `$scope.updateModel()`, the model updates after 2 seconds, but I notice that the UI is flickering as the digest cycle seems to be triggered multiple times. I've tried wrapping the `$timeout` call in `$scope.$apply()` to control the digest cycle, but it throws an behavior saying `behavior: $apply already in progress`. Is there a recommended pattern to use `$timeout` without causing excessive digest cycles? Iโd also like to confirm if thereโs any way to ensure that the model update triggers a single digest cycle and doesnโt cause flickering in the UI. Any insights would be greatly appreciated! For context: I'm using Javascript on Linux. Is there a better approach? What's the best practice here?