Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error: Undefined data – How to find the problem? – Angular

From a webService, I would like to display some data. For example: LABEL, ISINCODE, REF.

In JSON, the structure is presented like this:

MET = [
  {
    LABEL: "WILHELMSEN",
    ISINCODE: "NO0010571698",

    RESOLUTION: [
      {
        REF: "01",
      },
    ],

  },

];

The method that will retrieve the data is called getData().

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

export class ShareholderInformationDetailsComponent implements OnInit {

    private unsubscribe$ = new Subject < void > ();

    arrayMets: ArrayMet[] = [];

    constructor(private service: ShareholderInformationDetailsService) {}


    ngOnInit(): void {
        this.getData();
    }

    getData(): void {
        this.service.getShareholdersDetails().pipe(
            takeUntil(this.unsubscribe$)
        ).subscribe(res => {
            if (res.RETURNCODE === ApiResponseCodeEnum.Ok) {
                console.log("First console ");
                console.log(JSON.stringify(res));
                console.log("---------------");
                console.log("Second console ");
                this.arrayMets = res.ARRAY_MET;
                console.log(JSON.stringify(this.arrayMets))
            }
        });
    }


}

In the first console.log I wanted to check if the webService was communicating with the front-end. I get data.

enter image description here

However, I don’t understand why I don’t see anything in the second console.log?

I get an undefined error message…

In InformationResponse file, I don’t see what I typed wrong?

export interface InformationResponse extends ApiResponse {
    ARRAY_MET: ArrayMet[];
}

export interface ArrayMet {
    LABEL: string;
    ISINCODE: string;
    RESOLUTION: RESOLUTION[];
}; 

export interface RESOLUTION {
    REF: number; 
}

Thanks

>Solution :

There is no ARRAY_MET but a MET key in your object; Your interface is wrong.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading