Exploring the functionality of $timer in angularjs for countdowns has been an interesting journey. While resources are abundant for creating basic count up or countdown timers like this example, my current challenge is looping through an array of integers to countdown each one individually to 0.
Here's a snippet of my HTML code:
<!doctype html>
<html ng-app>
... (omitted for brevity)
</html>
And here's my JavaScript code:
function AlbumCtrl($scope,$timeout) {
$scope.counterArray = [5,10,15];
$scope.onTimeout = function(){
for(var i = 0; i < counterArray.length; i++){
$scope.counterArray[i]--;
if ($scope.counter > 0) {
mytimeout = $timeout($scope.onTimeout,1000);
}
}
}
var mytimeout = $timeout($scope.onTimeout,1000);
}
The goal is to display a countdown from 5 to 0, then 10 to 0, and finally 15 to 0 at 1-second intervals. Even after tweaking the jsfiddle example and incorporating an integer array and loop, I'm facing some challenges.
JSBin link: http://jsbin.com/vaqene/1/edit
If you have any suggestions on how to tackle this issue, your insights would be much appreciated!