Function 2 relies on the return of Function 1, while Function 3 uses both returns. How can I clean up this process? Currently, Function 3 is only giving me undefined values.
Below are my 3 functions:
Function1
$scope.nombreCompetencesATraiter = function(){
var nbr = 0;
notesService.getNotesByCollaborateurId($scope.idCollaborateurSelectionne).then(function(data){
$scope.myNotes = data;
angular.forEach($scope.myNotes, function(valueNote, keyNote) {
if ((valueNote.status === "EN_ATTENTE_DE_VALIDATION") || (valueNote.status === "EN_ATTENTE_DE_SUPPRESSION")){
nbr++;
}
})
console.log(nbr);
return nbr;
})
}
Function 2
$scope.affinerConfigBoutonsCompetences = function() {
nbCompetenceATraiter = $scope.nombreCompetencesATraiter();
if (nbCompetenceATraiter == 0){
$scope.radioModelFilterToutesLesCompetences = true;
$scope.radioModelFilterCompetencesAValider = false;
}
else{
$scope.radioModelFilterCompetencesAValider = true;
$scope.radioModelFilterToutesLesCompetences = false;
}
}
Function 3
$scope.affinerConfigBoutonsCompetencesThen = function(){
$q.all([$scope.nombreCompetencesATraiter(), $scope.affinerConfigBoutonsCompetences()]).then(function(value) {
console.log(value[0]);
console.log(value[1]);
})
}
Any advice would be greatly appreciated. Thank you!