I'm trying to access a property from a function but for some reason it gives an undefined error.
export class InserterComponent implements OnInit {
public imagenActual: string = 'John';
contador: number = 0;
imagenes = IMAGENES;
imagen: Imagen = {
numero: 1,
url: 'peter'
}
Here's the interface imagenes
import { Imagen } from './imagen';
export const IMAGENES: Imagen[] = [
{ numero: 1, url: 'Dr Nice' },
{ numero: 2, url: 'Narco' },
{ numero: 3, url: 'Bombasto' },
{ numero: 4, url: 'Celeritas' },
{ numero: 5, url: 'Magneta' },
{ numero: 6, url: 'RubberMan' },
{ numero: 7, url: 'Dynama' },
{ numero: 8, url: 'Dr IQ' },
{ numero: 9, url: 'Magma' },
{ numero: 0, url: 'Tornado' }
];
And here's the function that gives the error (error appears at "this.imagenes"):
public startSession() {
setInterval(this.funct, 2000);
};
public funct() {
this.imagenActual = this.imagenes[this.contador].url;
setTimeout(alert, 50000);
this.contador++;
}