这是列表html中的代码 list.component.html
<div nz-row formArrayName="tasks">
<ng-container *ngFor="let tasks of getTasks(taskFormGroup);let i = index">
<div nz-col nzXXl="12">
<div nz-col nzSpan="8">
<label [textContent]="tasks?.value?.task?.name"></label>
</div>
<div nz-col nzSpan="8">
<nz-form-item>
<nz-form-control>
<nz-radio-group [formControlName]="tasks.get('failed')">
<label nz-radio nzValue="true">Passed</label>
<label nz-radio nzValue="false">Failed</label>
</nz-radio-group>
</nz-form-control>
</nz-form-item>
</div>
<div nz-col nzSpan="8">
<nz-form-item>
<nz-form-control>
<textarea nz-input formControlName="remarks" placeholder="Placeholder" class="remarks-textarea"
type="text"></textarea>
</nz-form-control>
</nz-form-item>
</div>
</div>
</ng-container>
</div>
列表打字稿中的代码 list.component.ts
createTaskFormGroup() {
const list = this.store.selectSnapshot(ConfigurationState.get('collections'));
const formArray: any = [];
if (Array.isArray(list.checklists)) {
list.checklists.map((data: any) => {
data.tasks.forEach((task: any) => {
formArray.push({
failed: false,
remarks: '',
task: task
});
});
});
}
console.log(formArray, '+++');
return this.fb.group({
remarks: new FormControl(['', [Validators.required]]),
tasks: this.fb.array([formArray])
});
}
getTasks(form: any) {
return form.controls.tasks.controls;
}
如何解决错误ERROR Error: Cannot find control with path: 'tasks -> '
(<nz-radio-group [formControlName]="tasks.get('failed')">
)以及无法通过路径找到控件的文本区域
错误在nz-radio-group
中,错误是cannot find control with path:
谢谢。
答案 0 :(得分:0)
您必须将ngFor包装在 formArrayName
中<div formArrayName="tasks">
<ng-container *ngFor="let tasks of getTasks(taskFormGroup);let i = index">
....
</div>