In the code console.log(this.gameIndex) prints out undefined. Why is this? When I console.log(this.gameIndex) within the constructor the correct value is printed out.
Typescript
export class HomeComponent implements OnInit {
game:String;
gameIndex;
games:String[];
constructor() {
this.gameIndex = 0;
this.games = ['game1','game2','game3'];
this.game = this.games[this.gameIndex];
setInterval(this.rotatingBackground,3000);
console.log(this.gameIndex);
}
ngOnInit() {
}
rotatingBackground():any {
console.log(this.gameIndex);
this.game = this.games[this.gameIndex];
console.log(this.game);
}
}