0

How $timeout works in angularJs? And how it's different from setTimeOut()?

1
  • I think that's solve my problem. Thanks -@JonKoops Commented May 15, 2016 at 15:37

2 Answers 2

0

$timeout run a function after a defined delay :

$timeout(yourFunction, yourDelayInMS) 

For sample display an alert after one second:

$timeout(function(){alert('hello'},1000);

The difference between $timeout against setTimeout is $timeout is a part of the digest cycle of angularjs. if you modify the scope in your code it's better to use $timout instead of setTimeout.

Sign up to request clarification or add additional context in comments.

Comments

0

for example if you use setTimeout in your link function the $scope variables won't change. Instead you need to do something like that

window.setTimeout(function() {
  scope.$apply(function() {
    scope.myVar = "I changed"
  })
},1000);

$timeout just wraps that for you.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.