Dealing with asynchronous calls in Angular can be tricky. One common issue is getting an array as undefined due to the asynchronous nature of the calls. How can this be solved?
private fetchData(id){
var array = [];
this.httpClient.get('someUrl/'+id).subscribe((organisation)=> {
console.log(organisation.teams); // ['team1','team2','team3']
organisation.teams.forEach((team) => {
this.httpClient/get('someUrl/'+team).subscribe((teamData) => {
array.push(teamData);
})
})
console.log(array); // undefined
})
}