如何解决错误:找不到带有角形路径的控件

时间:2019-12-17 07:02:57

标签: javascript angular typescript

这是列表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:

谢谢。

1 个答案:

答案 0 :(得分:0)

您必须将ngFor包装在 formArrayName

<div formArrayName="tasks"> 
   <ng-container *ngFor="let tasks of getTasks(taskFormGroup);let i = index">
   ....

</div>