<tr *ngFor="let p of personen; let i=index">
<td> <input [(ngModel)]="p.Vorname" name="p.Vorname" type="text" class="form-control" required ></td>
<td> <input [(ngModel)]="p.Nachname" name="p.Nachname" type="text" class="form-control" required ></td>
<td> <input [(ngModel)]="p.Geburtsdatum" name="p.Geburtsdatum" type="date" class="form-control" required ></td>
<button (click)="premove(i)" type="button" class="btn btn-danger">Entfernen</button>
</tr>
如果我使用
添加新项目 this.personen.push(new Person())
我阵列中的数据&#39; personen&#39;没问题,但我页面上的输入字段显示为空。
答案 0 :(得分:1)
确保name
属性是唯一的:
<tr *ngFor="let p of personen; let i=index">
<td> <input [(ngModel)]="p.Vorname" name="Vorname{{i}}" type="text" class="form-control" required ></td>
<td> <input [(ngModel)]="p.Nachname" name="Nachname{{i}}" type="text" class="form-control" required ></td>
<td> <input [(ngModel)]="p.Geburtsdatum" name="Geburtsdatum{{i}}" type="date" class="form-control" required ></td>
<button (click)="premove(i)" type="button" class="btn btn-danger">Entfernen</button>
</tr>