【发布时间】:2019-03-07 06:57:32
【问题描述】:
我正在尝试创建具有角度形式的 PrimeNg 可编辑表格。
app.component.ts(这是最小的可重现代码)
export class AppComponent implements OnInit {
epForm: FormGroup;
range: FormArray;
constructor(private fb: FormBuilder,){
}
ngOnInit() {
this.epForm = new FormGroup({});
this.epForm.addControl('range', new FormArray([]));
this.range = <FormArray>this.epForm.get('range');
this.range.push(
this.fb.group({
type: ['X1 Gene']
})
);
}
}
html文件是
<form [formGroup]="epForm" novalidate>
<p-table [value]="epForm.controls.range.value" [rows]="10" [responsive]="true">
<ng-template pTemplate="header">
<tr> Range </tr>
</ng-template>
<ng-template pTemplate="body" let-i="rowIndex">
<tr [formGroupName]='i'>
<td >
<input type="text" pInputText formControlName="type" />
</td>
</tr>
</ng-template>
</p-table>
</form>
我尝试使用上面的代码显示内容,但我无法编辑输入标签。我打开检查元素并检查它,只有tbody 是keyon 更新。
我删除了[formgroup]='i',并在控制台中检查了它,但出现以下错误
Cannot find control with path: 'range -> type'
我用<table> 尝试过同样的事情,它工作正常。但是使用 p-table 我得到了这种行为?我该如何解决这个问题。
像下面的图片一样,我正在检查元素中,[formGroupName]
【问题讨论】:
-
将
[formGroupName]='i'替换为formGroupName='i' -
我尝试了但没有工作,我收到了
Cannot find control with path: 'range -> i' -
你有没有找到一种方法来使用primeng editable with formarray?我面临同样的问题,一些问题很多
-
@Liem 我使用 trackby 函数解决了这个问题,你可以在答案部分看到我的答案。
标签: angular primeng angular-forms