我有像这样的表格组

this.PatientInfo = this.fb.group({
      PatientID: [0],
      Gender: '',
      Name:'',
      Employer: this.fb.group({
        EmployerID: 0,
        Name: [''],
        EmployerAddresses: this.fb.group({
          Address1: [''],
          Address2: [''],
          CityName: [''],
          District: [''],
          StateName: [''],
          PostalCode: [''],
          Country: ['']
        })
      })
    });
而且我像这样绑定(bind)数据
<div class="col-md-3" formGroupName="EmployerAddresses">
    <div class="form-group form-group-default">
        <label class="control-label">State</label>
        <div class="input-group">
            <input type="text" class="form-control" formControlName="StateCode">
        </div>
    </div>
 </div>
最重要的是,我将表单组保留为PatientInfo。
在这里,我收到错误消息“找不到名称为EmployerAddresses的控件”。
能否请任何人帮忙。提前致谢。

最佳答案

这段代码解决了我的问题。

this.PatientInfo = this.fb.group({
  PatientID: [0],
  Gender: '',
  Name:'',
  Employer: this.fb.group({
    EmployerID: 0,
    Name: [''],
    EmployerAddresses: this.fb.group({
      Address1: [''],
      Address2: [''],
      CityName: [''],
      District: [''],
      StateName: [''],
      StateCode: [''],
      PostalCode: [''],
      Country: ['']
    })
  })
});

<div class="col-md-3" formGroupName="Employer">
  <div class="form-group form-group-default" formGroupName="EmployerAddresses">
      <label class="control-label">State</label>
      <div class="input-group">
          <input type="text" class="form-control" formControlName="StateCode">
      </div>
  </div>
</div>

谢谢...

10-06 15:25