找不到路径控制:Angular 4

时间:2018-02-09 10:33:04

标签: ionic3 angular4-forms

我有这样的表单生成器:

  initForm() {
    return this.generalForm= this.formBuilder.group({
      startDate: [new Date().toISOString(),Validators.compose([Validators.required])],
      hour:this.formBuilder.array([
        this.formBuilder.group({startHour: [Validators.compose([Validators.required])]})
      ]),
      laboratory: this.formBuilder.group({id:[Validators.compose([Validators.required])]}),
    });
  }

在html中,我遇到了一个问题,就像我在组件上一样呈现表单。

<div formArrayName="hour">
          <div *ngFor="let hour of generalForm.controls.hour.controls; let i=index">
            <div  [formGroupName]="i">
              <ion-item>
                <ion-label >Hour </ion-label>
                <ion-datetime displayFormat="HH:mm" formControlName="startHour"></ion-datetime>
              </ion-item>
            </div>
          </div>
        </div>

我试过这个。我有这个错误:

 Cannot find control with path: 'hour -> 0 ->  startHour'

如何解决问题?

0 个答案:

没有答案