I am fully aware of why my variable is undefined in this scenario.
At the beginning of the page, I declare an object named section with the following instantiation:
section: Section;
Further down in the ngOnInit
function, I utilize a promise to retrieve a value from local storage and assign it to the section variable as shown below:
this.storage.get(CERTIFICATE).then(res => {
this.certificate = JSON.parse(res);
this.storage.get(SECTION).then(uuid => {
this.certificate.sections.forEach(section => {
if (section.uuid !== uuid) {
return;
}
this.section = section;
});
});
});
This implementation works flawlessly. I then make use of this section variable in sections.page.html like so:
<app-section [section]="section"></app-section>
However, upon initial page load, I encounter a 'section is undefined' error. It resolves promptly once the promise returns.
To handle this error, I attempted initializing the section variable with:
section: Section = new Section();
Unfortunately, this approach didn't resolve the issue.
The structure of the Section model is as follows:
import {Question} from './Question';
export class Section {
id: number;
uuid: string;
title: string;
questions: Question[];
}
Could the absence of a 'constructor' be causing this error? Is there any alternative method to prevent this error?
ERROR TypeError: "_co.section is undefined"