I am currently facing a priority issue in my code. The problem arises when I call a web service and attempt to retrieve usernames based on user IDs from an array (listePasseoDemandesEnCours) using a foreach loop.
this.ws_demandes_en_cours.getDemandesEnCours().subscribe(
(ws_data: IAPIListeDemandes) => {
this.isLoading = false;
this.userId = this.user_info.getUserID();
ws_data.listePasseoDemandesEnCours.forEach(item => {
if (this.userId === item.demandeur) {
this.userName = item.demandeur_nomPrenom;
console.log(this.userName +' test username');
}
});
Following the foreach loop, I store the retrieved usernames in another array.
this.selectionUser.push(this.userName);
console.log(this.userName +' test push user in selectionUserArray')
The issue lies in attempting to access the username value before the foreach loop completes, resulting in an undefined value. Ideally, I would like the loop to finish executing and only then check if the username is not empty before pushing it into the array.