4
votes

I'm facing the following error :

EXCEPTION: Uncaught (in promise): Error: Error in ./AccComponent class AccComponent - inline template:106:11 caused by: Cannot find control with name: 'det'

my formbuilder is the following :

this.AccForm = this.fb.group({
      accid: ['', Validators.required],
      accnbr: ['', Validators.required],
      cyc: this.fb.group({
        cycid:['', Validators.required],
        name:['', Validators.required],
        description:['', Validators.required],  
        det: this.fb.group({
          dcycid: ['', Validators.required],
          status: ['', Validators.required],
        })
      })
    });

And in my template when I tried to get the formgroupname 'det' I got the error ?

    <div formGroupName="det">
           <div class="row">
             <div class="form-group>
                <span><strong>Id</strong></span>
                <input formControlName="dcycid" id="dcycid" type="number" class="form-control">
              </div>    
             <div class="form-group">
                <span><strong>status</strong></span>
                <input formControlName="status" id="status" type="text" class="form-control">
             </div>
           </div>
    </div>

Remark the 'det' is nested in the 3th level.

Any idea what's wrong ?

Thank you.

/KOul

1

1 Answers

6
votes

Please find the Corrected HTML, what you need to do is nest the FormGroupNames as per the JSON

<div [formGroup]="AccForm">
 <div formGroupName="cyc">
  <div formGroupName="det">
  <div class="row">
    <div class="form-group">
      <span><strong>Id</strong></span>
      <input formControlName="dcycid" id="dcycid" type="number" class="form-control">
    </div>
    <div class="form-group">
      <span><strong>status</strong></span>
      <input formControlName="status" id="status" type="text" class="form-control">
    </div>
  </div>
</div>