【发布时间】:2019-08-06 11:32:50
【问题描述】:
我想在 *ngFor 循环中添加一个表单。下面是我尝试重复一个按钮,如下所示:
html 文件:
<div *ngFor="let passenger of passengerForm;let i=index;">
<form>
<mat-form-field>
<input matInput type="text" placeholder="Enter Name"
[(ngModel)]="passenger.Name">
</mat-form-field>
</Form>
<div>
<button (click)="addFieldValue(i); ">
Add Passenger
</button>
</div>
</div>
打字稿文件:
newAttribute ={}
addFieldValue(index) {
if ( index < 3) {
this.passengerForm.push(this.newAttribute )
this.newAttribute = {};
}
}
【问题讨论】:
-
如果问题仍然存在,则为 stackblitz 提供预期输出
标签: angular typescript angular-material angular6