B
B
babai192015-03-19 16:02:58
JavaScript
babai19, 2015-03-19 16:02:58

What is the difference between setTimeout and $timeout?

What is the difference between setTimeout and $timeout in angularjs?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Arthur, 2015-03-19
@babai19

The most important thing is that $timeout updates the scope (any data on the page will change), and a simple setTimeout will not update anything in the scope (the data on the page will be old as it was).
Most importantly, $timeout is by no means a substitute for setTimeout!!!
If you have a functionality that works with scope data and binds variables, then use $timeout, if you just need to execute something on a timeout (for example, do something once a second, then, after a second, again, and so further, but not related to updating the scope data), then use setTimeout. Tobish, $timeout starts a $digest-cycle and redraws the page - just imagine if you redraw the page every second.

A
Andrew, 2015-03-19
@couchemar

https://docs.angularjs.org/api/ng/service/$timeout

I
Igor Kalashnikov, 2015-03-19
@zo0m

use $timeout
in setTimeout() you will also have to handle $scope.$apply() , for binds

T
TekVanDo, 2015-03-19
@TekVanDo

If not detailed $timeout executes the function in via $digest

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question