angular - angular2 és Typescript tömb - A 'push' tulajdonság nem létezik a '() => void' típuson
Hogyan inicializálok egy üres tömböt?
test: any[];
//On change I want to add an item to an array
test(){
this.test.push('a');
}
error TS2339: A 'push' tulajdonság nem létezik a '() => void' típuson.
Válasz #1
Nem inicializálod a tömbödet, így a test undefined. Ahhoz, hogy használni tudd, egyszerűen inicializáld így:
test: any[] = [];
