I'm trying to add an array of Funcionarios objects into a Equipa object, but when i try to push a new Funcionarios it pops and this error TypeError: Cannot read property 'push' of undefined, i have gone over the code several times and initialized all variables, but it keeps always giving me the same error.
export class Funcionarios {
id : Number;
codFunc: Number;
nomeFunc: string;
constructor(codFunc: Number, nomeFunc: string) {
this.codFunc = codFunc;
this.nomeFunc = nomeFunc;
}
}
export class Equipa {
id : Number;
codEquipa: Number;
nomeEquipa: string;
ocorFuncs: Funcionarios[] = [];
constructor(id : Number, codEquipa: Number, nomeEquipa: string, funcs: Funcionarios[]) {
this.id = id;
this.codEquipa = codEquipa;
this.nomeEquipa = nomeEquipa;
this.ocorFuncs = funcs;
}
}
export class TestComponent implements OnInit {
equipa: Equipa = new Equipa(null, null, null, null);
ngOnInit() {
this.equipa.ocorFuncs.push(new Funcionarios(1, "qwe"));
this.equipa.ocorFuncs.push(new Funcionarios(2, "asd"));
this.equipa.ocorFuncs.push(new Funcionarios(3, "zxc"));
}
}
ngAfterViewInitinstead ofngOnInit