I have two angular.forEach
The second one musn't start untill the first one is finished :
$scope.rendezVous.j_plaignant = [];
angular.forEach(data.data,function(objet){
if(objet.idpartie==1){
$scope.rendezVous.j_plaignant.push(objet.idjuriste);
}
})
$scope.rendezVous.juristes_plaignant = [];
angular.forEach(data.data,function(objet){
if(objet.idpartie==1){
$scope.rendezVous.juristes_plaignant.push(objet);
}
})
I've tried this with no luck :
var defer = $q.defer();
$scope.rendezVous.j_plaignant = [];
angular.forEach(data.data,function(objet){
if(objet.idpartie==1){
$scope.rendezVous.j_plaignant.push(objet.idjuriste);
}
})
$q.all($scope.rendezVous.j_plaignant).then(lastTask);
function lastTask(){
$scope.rendezVous.juristes_plaignant = [];
angular.forEach(data.data,function(objet){
if(objet.idpartie==1){
console.log(objet);
$scope.rendezVous.juristes_plaignant.push(objet);
}
})
}
It would be nice if you have an idea, $q is difficult to understand.
I don't understand why i isn't possible to add a .then after a forEach., it is so annoying, i can't understand $q.