title: formGroupName must be used with a parent formGroup directive
body: <p>[EDIT] : that's why because i used formGroupName on form tag and it has to be on a div tag.
  There is an other problem with formArrayName, no errors but the checkbox associated didn't appears.
  I did this and now its says can't access controls of undefined..</p>
  
  <pre><code>get operatingRangesFormArray(): FormArray { return this.modifyForm.get('operatingRanges') as FormArray; }
  
  in template : 
          &lt;div ID="divChkBoxTimePicker" formGroupName="checkboxGroupOperatingRange" style="width: 100%;"&gt;
              &lt;div style="display:flex; flex-direction: row; align-items: center; justify-content: center;"&gt;
                  &lt;div class="col-md-6 flex-column-align-start"&gt;
                      &lt;div formArrayName="operatingRanges" *ngFor="let item of operatingRangesFormArray.controls; let i = index"&gt;
                          &lt;div class="row-no-wrap" *ngIf="i &lt; (operating_ranges.length - 1)/2"&gt;
                              &lt;label&gt;
                                  &lt;mat-checkbox [value]="operating_ranges[i]?.id" [formControlName]="i" style="margin-right: 5px;" (change)="updateDureeTotaleOperatingRanges($event)"&gt;
                                      {{operating_ranges[i]?.name}}
                                  &lt;/mat-checkbox&gt;
                              &lt;/label&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="col-md-6 flex-column-align-start"&gt;
                      &lt;div formArrayName="operatingRanges" *ngFor="let item of operatingRangesFormArray.controls; let i = index"&gt;
                          &lt;div class="row-no-wrap" *ngIf="i &gt; (operating_ranges.length - 1)/2"&gt;
                              &lt;label&gt;
                                  &lt;mat-checkbox [value]="operating_ranges[i]?.id" [formControlName]="i" style="margin-right: 5px;" (change)="updateDureeTotaleOperatingRanges($event)"&gt;
                                      {{operating_ranges[i]?.name}}
                                  &lt;/mat-checkbox&gt;
                              &lt;/label&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div *ngIf="!this.modifyForm.get('checkboxGroupOperatingRange').valid"&gt;Au moins une gamme opératoire doit être sélectionné&lt;/div&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>its been 2 days that i'm stuck on this little problem : formControlName must be used with a parent formGroup directive.</p>
  
  <p>I tried to use reactive forms tu update my big form and transform it to a formgroup which containing several formcontrol and 3 nested form groups.
  The structure is : </p>
  
  <pre><code>public equipmentLocationWorkFieldControl: FormControl = new FormControl('');
  public equipmentLocationStructureControl: FormControl = new FormControl('');
  public equipmentLocationLocalControl: FormControl = new FormControl('');
  public equipmentLocationPlaceControl: FormControl = new FormControl('');
  public equipmentLocationEquipmentTypeControl: FormControl = new FormControl('');
  public equipmentLocationEquipmentControl: FormControl = new FormControl('');
  public equipmentNameControl: FormControl = new FormControl('');
  public equipmentLocationEquipmentTypeNewControl: FormControl = new FormControl('');
  public equipmentLocationEquipmentTypeNew2Control: FormControl = new FormControl('');
  public equipmentSurnameControl: FormControl = new FormControl('');
  public equipmentSerialControl: FormControl = new FormControl('');
  public equipmentLocationBrandControl: FormControl = new FormControl('');
  public equipmentLocationModelControl: FormControl = new FormControl('');
  public equipmentLocationWorkFieldNewControl: FormControl = new FormControl('');
  public equipmentLocationEquipmentSelectedControl: FormControl = new FormControl('');
  public equipmentSelectedControl: FormControl = new FormControl('');
  public equipmentSelectedIdControl: FormControl = new FormControl('');
  public operatingRanges: FormArray = new FormArray([], this.minSelectedCheckboxes(1));
  public agentsDispo: FormArray = new FormArray([], this.minSelectedCheckboxes(1));
  public agentsInShiftSelected: FormArray = new FormArray([], this.minSelectedCheckboxes(1));
  public checkboxGroupAgentInShiftAndDispoAndIntervenant: FormGroup = new FormGroup({
      shiftControl: this.shiftControl,
      agentsInShiftSelected: this.agentsInShiftSelected,
      agentsDispo: this.agentsDispo,
      agentParticipantsControl: this.agentParticipantsControl,
      externalActorControl: this.externalActorControl,
      externalActorParticipantsControl: this.externalActorParticipantsControl,
  });
  public checkboxGroupOperatingRange: FormGroup = new FormGroup({
      operatingRanges: this.operatingRanges,
  });
  
  
  
  (IN NG_INIT FUNCTION)
  this.modifyForm = this.formBuilder.group({
          dateDeb: this.dateDeb,
          dateFin: this.dateFin,
          workTypeControl: this.workTypeControl,
          description: this.description,
          note: this.note,
          checkboxGroupOperatingRange: this.formBuilder.group({
              operatingRanges: this.operatingRanges,
          }),
          checkboxGroupAgentInShiftAndDispoAndIntervenant: this.formBuilder.group({
              shiftControl: this.shiftControl,
              agentsInShiftSelected: this.agentsInShiftSelected,
              agentsDispo: this.agentsDispo,
              agentParticipantsControl: this.agentParticipantsControl,
              externalActorControl: this.externalActorControl,
              externalActorParticipantsControl: this.externalActorParticipantsControl,
          }),
          equipmentLocationForm: this.formBuilder.group( {
              equipmentLocationWorkFieldControl: this.equipmentLocationWorkFieldControl,
              equipmentLocationStructureControl: this.equipmentLocationStructureControl,
              equipmentLocationLocalControl: this.equipmentLocationLocalControl,
              equipmentLocationPlaceControl: this.equipmentLocationPlaceControl,
              equipmentLocationEquipmentTypeControl: this.equipmentLocationEquipmentTypeControl,
              equipmentLocationEquipmentControl: this.equipmentLocationEquipmentControl,
              equipmentNameControl: this.equipmentNameControl,
              equipmentLocationEquipmentTypeNewControl: this.equipmentLocationEquipmentTypeNewControl,
              equipmentLocationEquipmentTypeNew2Control: this.equipmentLocationEquipmentTypeNew2Control,
              equipmentSurnameControl: this.equipmentSurnameControl,
              equipmentSerialControl: this.equipmentSerialControl,
              equipmentLocationBrandControl: this.equipmentLocationBrandControl,
              equipmentLocationModelControl: this.equipmentLocationModelControl,
              equipmentLocationWorkFieldNewControl: this.equipmentLocationWorkFieldNewControl,
              equipmentLocationEquipmentSelectedControl: this.equipmentLocationEquipmentSelectedControl,
              equipmentSelectedControl: this.equipmentSelectedControl,
              equipmentSelectedIdControl: this.equipmentSelectedIdControl,
              equipmentControl: this.equipmentControl,
          })
      });
  </code></pre>
  
  <p>The second problem is Cannot find control with name: 'equipmentControl' and  Cannot read property 'push' of undefined about these lines : </p>
  
  <pre><code> const control = new FormControl(false); // if first item set to true, else false
   (this.checkboxGroupAgentInShiftAndDispoAndIntervenant.controls.agents_dispo as FormArray).push(control);
  </code></pre>
  
  <p>Least but not last the template structure :</p>
  
  <pre><code>&lt;form *ngIf="modifyForm" [formGroup]="modifyForm" (ngSubmit)="modifyIntervention()"&gt;
      &lt;input matInput [matDatepicker]="picker" required placeholder="Choisir la date d'intervention" formControlName="dateDeb" (dateChange)="updateDate()"&gt;
      &lt;input matInput [matDatepicker]="picker1" required placeholder="Choisir la date de cloture" [value]="dateDeb.value" formControlName="dateFin"&gt;
      &lt;mat-select formControlName="workTypeControl" required [(value)]="selectedWorkTypeForMaincouranteModify"&gt;
                          &lt;mat-option [value]="0"&gt;Choisir une type de travail&lt;/mat-option&gt;
                          &lt;mat-option *ngFor="let item of work_types" [value]="item.id"&gt;{{ item.name }}&lt;/mat-option&gt;
                      &lt;/mat-select&gt;
      &lt;textarea matInput placeholder="Description" formControlName="description" required&gt;&lt;/textarea&gt;
      &lt;textarea matInput placeholder="Remarque" formControlName="note"&gt;&lt;/textarea&gt;
      &lt;form formGroupName="checkboxGroupOperatingRange" style="width: 100%;"&gt;
          &lt;div class="col-md-6 flex-column-align-start"&gt;
              &lt;div formArrayName="operatingRanges" *ngFor="let item of operatingRanges.controls; let i = index"&gt;
                  &lt;div class="row-no-wrap" *ngIf="i &lt; (operating_ranges.length - 1)/2"&gt;
                      &lt;label&gt;
                          &lt;mat-checkbox [value]="operating_ranges[i]?.id" [formControlName]="i" style="margin-right: 5px;" (change)="updateDureeTotaleOperatingRanges($event)"&gt;
                                                  {{operating_ranges[i]?.name}}
                          &lt;/mat-checkbox&gt;
                      &lt;/label&gt;
                  &lt;/div&gt;
               &lt;/div&gt;
           &lt;/div&gt;
           &lt;div class="col-md-6 flex-column-align-start"&gt;
               &lt;div formArrayName="operatingRanges" *ngFor="let item of this.modifyForm['controls'].checkboxGroupOperatingRange['controls'].operatingRanges.value; let i = index"&gt;
                   &lt;div class="row-no-wrap" *ngIf="i &gt; (operating_ranges.length - 1)/2"&gt;
                       &lt;label&gt;
                           &lt;mat-checkbox [value]="operating_ranges[i]?.id" [formControlName]="i" style="margin-right: 5px;" (change)="updateDureeTotaleOperatingRanges($event)"&gt;
                                                  {{operating_ranges[i]?.name}}
                           &lt;/mat-checkbox&gt;
                       &lt;/label&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
      &lt;/form&gt;
      &lt;form formGroupName="checkboxGroupAgentInShiftAndDispoAndIntervenant" style="width: 100%;"&gt;
          &lt;div class="divHiddenUnderButton" *ngIf="isOpenSaisieParticipant"&gt;
              &lt;mat-form-field style="display: inline !important;width: 100%;"&gt;
                  &lt;mat-select formControlName="shiftControl" required [(value)]="selectedShiftForMaincouranteModify" (selectionChange)="getAgentsInShiftAndDispo()"&gt;
                      &lt;mat-option [value]="0"&gt;Choisir la vacation&lt;/mat-option&gt;
                      &lt;mat-option *ngFor="let item of shifts" [value]="item.id"&gt;{{ item.name }}&lt;/mat-option&gt;
                  &lt;/mat-select&gt;
              &lt;/mat-form-field&gt;
              &lt;div ID="AgentVacation" style="display: inline !important;width: 100%;"&gt;
                  &lt;div class="col-md-6 flex-column-align-start"&gt;
                      &lt;div formArrayName="agentsInShiftSelected" *ngFor="let item of checkboxGroupAgentInShiftAndDispoAndIntervenant.controls.agentsInShiftSelected.controls; let i = index"&gt;
                          &lt;label *ngIf="i &lt; (agentsInShiftSelected.length-1)/2"&gt;
                          &lt;mat-checkbox [value]="agentsInShiftSelected[i]?.id" [formControlName]="i" style="margin-right: 5px;" &gt;
                                                  {{agentsInShiftSelected[i]?.firstname.charAt(0)}}.{{agentsInShiftSelected[i]?.lastname}}
                          &lt;/mat-checkbox&gt;
                          &lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="col-md-6 flex-column-align-start"&gt;
                      &lt;div formArrayName="agentsInShiftSelected" *ngFor="let item of checkboxGroupAgentInShiftAndDispoAndIntervenant.controls.agentsInShiftSelected.controls; let i = index"&gt;
                          &lt;label *ngIf="i &gt; (agentsInShiftSelected.length-1)/2"&gt;
                          &lt;mat-checkbox [value]="agentsInShiftSelected[i]?.id" [formControlName]="i" style="margin-right: 5px;" &gt;
                                                  {{agentsInShiftSelected[i]?.firstname.charAt(0)}}.{{agentsInShiftSelected[i]?.lastname}}
                          &lt;/mat-checkbox&gt;
                          &lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;                
          &lt;/div&gt;
          &lt;div class="flex-column-center" style="margin-top:10px;" *ngIf="selectedShiftForMaincouranteModify !== 0 &amp;&amp; isOpenSaisieVacation"&gt;
              &lt;div style="display:flex; flex-direction: row; align-items: center; justify-content: center;"&gt;
                  &lt;div formArrayName="agentsDispo" *ngFor="let item of checkboxGroupAgentInShiftAndDispoAndIntervenant.controls.agentsDispo.controls; let i = index"&gt;
                      &lt;label *ngIf="i &lt; (agentsDispo.length-1)/2"&gt;
                      &lt;mat-checkbox [value]="agentsDispo[i]?.id" [formControlName]="i" style="margin-right: 5px;" &gt;
                                                      {{agentsDispo[i]?.firstname.charAt(0)}}.{{agentsDispo[i]?.lastname}}
                      &lt;/mat-checkbox&gt;
                      &lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div formArrayName="agentsDispo" *ngFor="let item of checkboxGroupAgentInShiftAndDispoAndIntervenant.controls.agentsDispo.controls; let i = index"&gt;
                      &lt;label *ngIf="i &gt; (agentsDispo.length-1)/2"&gt;
                      &lt;mat-checkbox [value]="agentsDispo[i]?.id" [formControlName]="i" style="margin-right: 5px;" &gt;
                                                      {{agentsDispo[i]?.firstname.charAt(0)}}.{{agentsDispo[i]?.lastname}}
                      &lt;/mat-checkbox&gt;
                      &lt;/label&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;mat-select formControlName="agentParticipantsControl" required [(value)]="selectedAgentParticipantsForMaincouranteModify"&gt;
              &lt;mat-option *ngFor="let item of participants" [value]="item.id"&gt;{{item.firstname.charAt(0)}}.{{ item.lastname }}&lt;/mat-option&gt;
           &lt;/mat-select&gt;
           &lt;mat-select formControlName="externalActorControl" [(value)]="selectedExternalActorForMaincouranteModify"&gt;
               &lt;mat-option [value]="0"&gt;Choisir un intervenant externe&lt;/mat-option&gt;
               &lt;mat-option *ngFor="let item of external_actors" [value]="item.id"&gt;{{item.name}}&lt;/mat-option&gt;
           &lt;/mat-select&gt;
           &lt;mat-select formControlName="externalActorParticipantsControl" [(value)]="selectedExternalActorParticipantsForMaincouranteModify"&gt;
               &lt;mat-option *ngFor="let item of external_actor_participants" [value]="item.id"&gt;{{item.name}}&lt;/mat-option&gt;
           &lt;/mat-select&gt;
       &lt;/form&gt;
       &lt;form formGroupName="equipmentLocationForm"&gt;
           &lt;input formControlName = "equipmentLocationStructureControl"&gt;
           &lt;input formControlName = "equipmentLocationPlaceControl"&gt;
           &lt;input formControlName = "equipmentLocationWorkFieldControl"&gt;
           &lt;input formControlName = "equipmentLocationEquipmentTypeControl"&gt;
           &lt;input formControlName = "equipmentLocationEquipmentControl"&gt;
           ..........
       &lt;/form&gt;
       &lt;mat-select formControlName="equipmentControl" required [(value)]="selectedEquipmentForMaincouranteModify" (selectionChange)="updateOtherFields($event)"&gt;
           &lt;mat-option *ngFor="let item of equipments_participants" [value]="item.id"&gt;
                          {{item.name}}({{item.equipment_locations[0].structure.name}}[{{item.equipment_locations[0].structure_id}}]|
                          {{item.equipment_locations[0].local.name}}[{{item.equipment_locations[0].local_id}}]|
                          {{item.equipment_locations[0].place.name}}[{{item.equipment_locations[0].place_id}}])
           &lt;/mat-option&gt;
       &lt;/mat-select&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>When i writed the structure i noticed that my form group parent modifyForm is containing all others forms. the form end tag of modifyForm is containning all others sub forms. So idecided to remove the end tag of modifyForm to put it before the next formGroupName than the structure is : </p>
  
  <pre><code>&lt;form [formGroup] = ""&gt;
          &lt;input formControlName = ""&gt;
          ....
      &lt;form formGroupName = ""&gt;
          &lt;input formControlName = ""&gt;
          ....
      &lt;/form&gt;
      &lt;form formGroupName = ""&gt;
          &lt;input formControlName = ""&gt;
          ....
          &lt;div formArrayName="operatingRanges" *ngFor="let item of operatingRanges.controls; let i = index"&gt;
              &lt;label&gt;
              &lt;mat-checkbox [value]="operating_ranges[i]?.id" [formControlName]="i" style="margin-right: 5px;" (change)="updateDureeTotaleOperatingRanges($event)"&gt;
                                              {{operating_ranges[i]?.name}}
              &lt;/mat-checkbox&gt;
              &lt;/label&gt;
          &lt;/div&gt;
      &lt;/form&gt;
      &lt;form formGroupName = ""&gt;
          &lt;input formControlName = ""&gt;
          ....
      &lt;/form&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And now, the structure is the following one. Then the error is formGroupName must be used with a parent formGroup directive. AND formControlName must be used with a parent formGroup directive.</p>
  
  <pre><code>    &lt;form [formGroup] = ""&gt;
          &lt;input formControlName = ""&gt;
          ....
      &lt;/form&gt;
      &lt;form formGroupName = ""&gt;
          &lt;input formControlName = ""&gt;
          ....
      &lt;/form&gt;
      &lt;form formGroupName = ""&gt;
          &lt;input formControlName = ""&gt;
          ....
          &lt;div formArrayName="operatingRanges" *ngFor="let item of operatingRanges.controls; let i = index"&gt;
              &lt;label&gt;
              &lt;mat-checkbox [value]="operating_ranges[i]?.id" [formControlName]="i" style="margin-right: 5px;" (change)="updateDureeTotaleOperatingRanges($event)"&gt;
                                              {{operating_ranges[i]?.name}}
              &lt;/mat-checkbox&gt;
              &lt;/label&gt;
          &lt;/div&gt;
      &lt;/form&gt;
      &lt;form formGroupName = ""&gt;
          &lt;input formControlName = ""&gt;
          ....
      &lt;/form&gt;
  </code></pre>
  
  <p>Please someone can help to find why it don't recognize my formcontrol field ? Whats i did bad ? i following the documentation...</p>