I want 5 numbers ranging from 1 to 5 (numberOfScreen has value 5 which comes from the API captured in it) to be pushed into the array, but I am getting the below error
core.js:6241 ERROR TypeError: Cannot read property 'push' of undefined
Find the code snippet below:
screens: Array<number>;
numberOfScreen: number;
get screenNumbers(): Number[] {
for (let i = 1; i <= this.numberOfScreen; i++) {
this.screens.push(i);
}
return this.screens;
}
I am new to Typescript so I wanted to understand where I am going wrong.
screens: Array<number>;is not yet initialized.screens = [];