I am facing an issue when attempting to iterate over a nested array object using the code below. It seems to be throwing an error saying "undefined". Could this be related to Typescript or angular4?
import { Process, Event } from "./process";
export class ProcessComponent {
process: Process;
someMethod() {
for(let val of this.process.events) {
console.log(val.notes); // The console is displaying undefined.
}
}
process.ts
export class Process {
id: number;
includeSaturdays: boolean;
includeSundays: boolean;
events: Event[];
}
export class Event {
id: number;
date: number;
notes: string;
}
Sample data :
{
"id": 1572734,
"includeSaturdays": false,
"includeSundays": false,
"events": {
"event": [
{
"id": 1587532,
"date": 1483209000000,
"notes": "New year"
},
{
"id": 1587533,
"date": 1495909800000,
"notes": "Memorial day"
}]
}
}