SetTimeout in Angular doesn’t update scope

Yes, we have had your problem before, but fortunately it has a simple solution. It turns out that setTimeout does not ask the scope to update its data. Rather, even if you update the scope, the data is not applied in the HTML template. It’s a bit unpleasant, yes. But the solution is simple. You just have to use a service called $timeout, which replaces the usual setTimeout, but ensures that the new data from the scope travels to the view once the execution of the function is finished. You will have to inject the service: .controller(“timeoutController”, function($scope, $timeout){ Then you will have to use it the same as you came using setTimeout, but in this case $timeout: $timeout(functionWithDelay, 3000);

See also  litElement
Loading Facebook Comments ...
Loading Disqus Comments ...