I am using AngulaJs and Ionic.
I am trying to call a function every 3 seconds for 10 times only (this is why I am not using $interval). Thing is, the code below calls the function only once (while the debugging code to the console is called 10 times).
for (i = 0; i < 10; i++)
{
$timeout(function () {
$scope.play(); // this is the called function
console.log("progress bar: " + i);
}, 3000);
}
Any help will be appreciated,
Thanks in advance,
Pagugim
$scope.play()since my plunker works perfectly: plnkr.co/edit/izZvfrLrGxmLD5n0AnYS?p=preview. NOTE: what you are doing will not have the outcome that you think it will. It will quickly create 10 iterations, wait three seconds per the timeout and resolve them all simultaneously, since $timeout returns a promise and will not block. This should be a recursive operation, as Mike noted below.