In a few script I can find for instance
$timeout(function () { $scope.my = 1; });
instead of simply
$scope.my = 1;
What's the purpose to call $timeout without delay?
This '$timeout' service of AngularJS is functionally similar to the 'window. setTimeout' object of vanilla JavaScript. This service allows the developer to set some time delay before the execution of the function.
The $timeout service can be used to call another JavaScript function after a given time delay. The $timeout service only schedules a single call to the function. For repeated calling of a function, see $interval later in this text.
setTimeout in order to display an alert message after a timeout of at least 2000 milliseconds. Angular $timeout is a wrapper written for window. setTimeout in form of a try catch block which throws exceptions via $exceptionHandler service. $timeout accepts the function to be delayed, delay time, a boolean to invoke $.
Verifies that there are no pending tasks that need to be flushed. It throws an error if there are still pending tasks. This method is essentially an alias of $verifyNoPendingTasks (called with no arguments).
This is a hack. :) But usually the intention is to wait until the end of the $digest
cycle and then set $scope.my
to 1
. Timeouts are called after all watches are done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With