I have an Angular Model and I am trying to push it to an array to create repeater fields. The array is then iterated to create html fields in a component. However, while pushing to the array, an undefined error is thrown .
Here is the Model code:
export class TierModel { feeName: string; feeDescription: string; unit: string; tierStart: number; tierEnd: number; rate: number; };
And here is the code that pushes Model to array:
addForm() { const obj = new TierModel() obj[0].feeName = 'test'; obj[0].unit = 0; this.dataarray.push(obj); }
The aim is to use an index with the object and then push it to the array so that any modification is to be done before pushing it to the array would be done here using index.
Any help would be more than
this.dataarray
is empty?newlen
would be -1 andthis.dataarray[0]
would be undefinedobj
with an index since it isn't an array. useobj.feeName = 'test';
or `obj["feeName"] = 'test'; insteadaddForm()
again and another object will be created/added. maybe you should explain you problem/goal more precisely