PrimeNG 模板中的表单不显示
Form within PrimeNG Template not displaying
我在 PrimeNG 的 turbotable 中定义了一个表单。该表单的目的是为位于 table 页脚的 table 创建另一个条目(组)。不幸的是它没有显示。知道为什么吗?
<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),
//...
});
我想使用表单,因为创建新组需要所有字段,我认为这是处理它的最佳方式。如果您有更好的建议欢迎提出。
我解决了我自己的问题。我只是删除了 form-tag,而是将 formGroup 附加到 tr-tag。
我在 PrimeNG 的 turbotable 中定义了一个表单。该表单的目的是为位于 table 页脚的 table 创建另一个条目(组)。不幸的是它没有显示。知道为什么吗?
<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),
//...
});
我想使用表单,因为创建新组需要所有字段,我认为这是处理它的最佳方式。如果您有更好的建议欢迎提出。
我解决了我自己的问题。我只是删除了 form-tag,而是将 formGroup 附加到 tr-tag。