Within an array I established, I am encountering an undefined value when I use console.log.
Take a look at my component.ts below:
export class OrderExceptionReportComponent implements OnInit {
public sessionData: ExceptionReportSessionData[] = [];
newData: any;
reports = [];
constructor(private orderExceptionReportService: OrderExceptionReportService) {
}
public async getExceptionReportSessionData(): Promise<void> {
return this.orderExceptionReportService.GetExceptionReportSessionData()
.then(
data => {
this.sessionData = data;
});
}
async ngOnInit() {
await this.getExceptionReportSessionData();
}
sessionDataChange(evt) {
const value = evt.target.value;
console.log(`session index: ${value}`);
console.log(this.sessionData);
if (isNaN(Number(value))) {
this.reports = [];
} else {
this.reports = this.sessionData[Number(value)].ReportFiles;
}
console.log(this.reports);
}
}
While console.log(this.sessionData)
correctly displays the array of data, console.log(this.reports)
within my sessionDataChange()
function shows an undefined value. This is crucial for a dropdown menu I'm working on. How can I ensure that this.reports
is assigned the correct value?
Here is the console output for reference: https://i.stack.imgur.com/UxEVZ.png