2

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

6
  • What do you see on the console when executing console.log(this.sessionData)? Can you add that structure to your post? Commented Jun 8, 2020 at 23:01
  • @bjdose added console photo Commented Jun 8, 2020 at 23:08
  • are you sure to enter else condition ? Commented Jun 8, 2020 at 23:09
  • 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. Commented Jun 8, 2020 at 23:10
  • this is typio. object names are case sensetive. change to reportFiles Commented Jun 8, 2020 at 23:11

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.