I am working on an Angular 4 project, I currently have a *ngFor, and in the loop we are creating a new form (so I could end up with 2 or more forms)
The problem I am having is, the [(ngModel)] is not binding to the array key.
Code examples below:
Definition of the new Array:
public newItem: Array<{ category_id: number, name: string, number_of_people_invited: number, number_of_people_confirmed: number }> = [];
then the form
<div *ngFor="let guestListItem of guestListItems; let i = index;">
<form (submit)="doSubmit(i)" [name]="i">
<ion-row ion-list>
<ion-col size="6">
<ion-item lines="none">
<ion-input name="name"
[(ngModel)]="newItem[i].name"
style="border: none" type="text"
placeholder="Family name"></ion-input>
</ion-item>
</ion-col>
<ion-col size="6">
<ion-item lines="none">
<ion-input name="number_of_people_invited"
[(ngModel)]="newItem[i].number_of_people_invited"
type="tel" placeholder="No. Guests"></ion-input>
<ion-button type="submit" end>Add</ion-button>
</ion-item>
</ion-col>
</ion-row>
</form>
</div>
The error am getting is: GuestListPage.html:20 ERROR TypeError: Cannot read property 'name' of undefined
this is line 20 : [(ngModel)]="newItem[i].name"