【发布时间】:2019-07-30 11:35:29
【问题描述】:
我在 PrimeNG 的涡轮机中定义了一个表格。表单的目的是为位于表尾的表创建另一个条目(组)。不幸的是它没有显示。知道为什么吗?
<ng-template pTemplate="footer" let-columns>
<form [formGroup]="groupForm" (ngSubmit)="createGroup()">
<tr>
<td>
<button pButton type="submit" icon="pi pi-plus"
[disabled]="!groupForm.valid" pTooltip="add group"></button>
</td>
<td *ngFor="let col of columns">
<input pInputText type="text" [formControlName]="col.field">
</td>
</tr>
</form>
</ng-template>
col 只是组件中的一个数组,它定义了一些数据,例如列大小和组的关联字段。
col.field 值当然与定义的 FormGroup 的控件名称匹配。
groupForm: FormGroup = new FormGroup({
field1: new FormControl('', Validators.required),
//...
});
我想使用表单,因为创建新组需要所有字段,我认为这是处理它的最佳方式。如果您有更好的建议,请随时提出。
【问题讨论】:
标签: angular typescript primeng angular-reactive-forms