How do I init an empty array?
test: any[];
//On change I want to add an item to an array
test(){
this.test.push('a');
}
error TS2339: Property 'push' does not exist on type '() => void'.
You don't initialize your array, so test
is undefined
. To be able to use it, just initialize it this way:
test: any[] = [];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With