I have a read priority problem in my code. Here, i call a web service, in this web service i put a foreach on an array (listePasseoDemandesEnCours) and I try to recover the username with the userid.
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');)}
and after the foreach, i put the username in another array
this.selectionUser.push(this.userName);
console.log(this.userName +' test push user in selectionUserArray')
The problem is that it tries to read the value of Username before the foreach is finished so it is undefined, I would like it to end the foreach and once the value of username != '' Then it the push in the table