JCA
JCA

Reputation: 287

Value won't assign to array after calling function Angular 9

I am getting an undefined value in an array I've set up when I console.log it.

Below is my component.ts:

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);
  }


}

When I console.log(this.sessionData) I am able to see my array of data just fine. But when I console.log(this.reports) from my sessionDataChange() function it logs an undefined value. I need that value for a drop down menu I am implementing. What can I do to make sure this.reports gets assigned the correct value?

Here is the console: enter image description here

Upvotes: 2

Views: 327

Answers (1)

bjdose
bjdose

Reputation: 1309

I see you are trying to get .ReportFile with R uppercase but in the image of the console I see reporteFiles with r lowercase. Try to change it and it will fix your problem.

Upvotes: 1

Related Questions