Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Callback to $interval function

How can I make sure the function runAfterLoopFinishes() runs after the $interval has finished? Right now it runs immediately after loop is first defined.

var loop = $interval(function () {
  // Do something great 10 times
}, 1000, 10);

// To run after looping
runAfterLoopFinishes();
like image 897
sir_thursday Avatar asked Sep 28 '26 08:09

sir_thursday


1 Answers

$interval returns a promise.

var loop = $interval(function () {
  // Do something great 10 times
}, 1000, 10);

loop.then(function(){
  // To run after looping
  runAfterLoopFinishes();
}

An $interval promise will be notified after each iteration, but only resolve after the last.

like image 189
André Werlang Avatar answered Sep 29 '26 20:09

André Werlang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!