I’m just trying to display with a simple console.log() the data I’m retrieving from a service I’m using.
I’m getting the data in form of this interface:
export interface ICommessa {
id: string;
numero: string;
descrizione: string;
checkList: ICheckList[];
}
that contains checkList, a list of the interface:
export interface ICheckList {
id: string;
nome: string;
}
In the component the variable is declared like this
public commesse: ICommessa[] = [];
For now I’m only trying to make sure the data arrives so I’m using this function that gets called in ngOnInit:
getCommesse(){
this.commesseService.getCommesse().subscribe(
(data) => {
this.commesse = data;
console.log(this.commesse[0]); //1
console.log(this.commesse[0].checkList); //2
});
}
At the line labeled 1 I get the whole object correctly with all the data I’m asking for included the checkList list with all the data inside of it too, but at the next line labeled 2 it gives me undefined as you can see here:
Also if I try accessing data
directly the same way I did with this.commesse
I get the same result. Still same if I use this.commesse[0]?.checkList
.