I'm currently facing an issue with my code and I'm a bit puzzled as to where the problem lies. The console is displaying the correct data for this.allNominations
, but it appears that the third for-loop is not being executed at all. As a result, the values in nominationDepartmentMap
are not being populated. I understand that my question may lack clarity, but any assistance would be greatly appreciated!
async getAllNominations() {
this.loadingAllNominations = true;
for (let nominee of this.allNominees) {
this.apiService.getNominations(nominee.email).subscribe((data) => {
this.allNominations.push(...data);
});
}
console.log( this.allNominations);
let nominationDepartmentMap = new Map<number, Nomination[]>();
for (let department of this.departments) {
nominationDepartmentMap.set(department.id, []);
}
for (let nomination of this.allNominations) {
console.log('hello')
for (let department of this.departments) {
if (nomination.nominee.departmentId == department.id) {
if (!nominationDepartmentMap.has(department.id)) {
nominationDepartmentMap.set(department.id, []);
}
nominationDepartmentMap.get(department.id)!.push(nomination);
break;
}
}
}
console.log(nominationDepartmentMap);
}