I'm trying to push to the end of array a new value when onSubmit event is raised.
My code looks like this:
accounts: Account[] = [];
feeAccount: Account = new Account();
onSubmit(f: FormsModule) {
console.log('Fee account -> ' + this.feeAccount);
this.accounts.push(this.feeAccount);
}
The problem is that I'm getting an error: Cannot read property 'push' of undefined. in spite of correct value logged just before it tries to push. What could be wrong here? I believe it is defined if it is logged correctly in the same method, or am I getting something wrong?
accounts, it appears to be correctly defined in the code above but if you're getting that error it suggests that it can't accessthis.accountssuggesting it's been changed to undefined from an empty array.