Something unusual is happening with my code. Most answers I've seen online talk about waiting for data, but that's not the issue here; the JSON source is within the HTML itself.
An array of items mysteriously has a length of zero, causing the forEach
loop to fail. Here's the snippet with the console output:
// Container class
public inspectionTypes: SelectionOption[] = [];
// further down
public initializeInspectionTypes(types: any[]) {
if (types) {
types.forEach(t => {
this.inspectionTypes.push(t);
});
}
}
// Some other class
console.debug('Type:', typeof container.inspectionTypes);
console.debug('Is Array:', Array.isArray(container.inspectionTypes));
console.debug('Length:', container.inspectionTypes.length);
console.debug(container.inspectionTypes);
container.inspectionTypes.forEach(option => {
console.debug(option);
// this.inspectionTypes().push(option);
});
Even though the console shows the array as populated, its length remains 0
, leading to confusion. Check out the screenshot for more clarity:
https://i.sstatic.net/vTlax8co.png
To rule out any misunderstandings, here's another screenshot showing the logging of inspectionTypes
first in case you suspect it's being emptied somewhere: