JSFiddle - React, Tailwind, and code Playground
HTML
<body ng-app='myApp'>
<div ng-controller='MyCtrl'>
</div>
</body>
JavaScript
var app = angular.module('myApp', []);
app.controller('MyCtrl', function($scope, $q, $timeout) {
var temp = $q.when({});
var arr = [3, 2, 1];
arr.forEach(function(element) {
//function declaration rather than call?
temp = temp.then(function(){
delay(element);
});
})
function delay(timing) {
var deferred = $q.defer();
console.log('starting: ' + timing)
$timeout(function() {
console.log('ending: ' + timing);
deferred.resolve(timing);
}, timing * 1000);
return deferred.promise;
}
});