How to stop a function while all async call was done ? I have a foreach on a list who increment a var trough a async call or not (with if condition)
My code :
$scope.updateDureePeriodeList = function () {
var mttLoyer = 0
angular.forEach($scope.articleListDuree, function (value, key) {
if (value.selected) {
if (value.bOption) {
$scope.getTauxDevisRevOption(value.prixArt * value.qttArt).then(function (taux) {
mttLoyer += value.prixArt * value.qttArt * taux / 100;
})
}
else
mttLoyer += value.prixArt * value.qttArt * $scope.DureeEdit.taux / 100;
}
});
$scope.DureeEdit.periodeList = new Array();
$scope.DureeEdit.periodeList.push({
'numPeriode': 1,
'mttLoyer': parseFloat(mttLoyer).toFixed(2),
});
}
Problem: getTauxDevisRevOption is async and when I go in it, my function dont stop so it do the $scope.DureeEdit.periodeList.push at the end before mttLoyer was increment in the .then() of the async call...