0

component.ts :

 ngOnInit(): void {
 this.getVgAuditDetails();
 this.vgaReportForm = this.formBuilder.group({
  section_id: [this.sectionId],
  userId: [this.userObj.id],
  QuestionId: [this.questionId],
  answerDetails: this.formBuilder.array([]),
  vgaAuditNumber: [this.vgAudit.vga_audit_number],
  clientId: [this.clientId]
});
}
newAnswerDetails(): FormGroup {
return this.formBuilder.group({
  core: [''],
  vitalInterests: [''],
  bufferZones: [''],
  pivotalZones: [''],
  forwardPositions: [''],
  powerVaccums: [''],
  textbox1: [''],
  textbox2: [''],
  textbox3: [''],
  textbox4: [''],
  txtIntiative1: [''],
  txtIntiative2: [''],
  txtIntiative3: [''],
  txtOperatingProperties1: [''],
  txtOperatingProperties2: [''],
  txtOperatingProperties3: [''],
  txtOperatingProperties4: [''],
  txtOperatingProperties5: [''],
  txtOperatingProperties6: [''],
});
}

addAnswerDetails(): void {
 this.answerDetails = this.vgaReportForm.get('answerDetails') as FormArray;
 this.answerDetails.push(this.newAnswerDetails());
}

onSubmit(){
 console.log(this.vgaReportForm.value);
}

compoent.html :

<form action="" [formGroup]="vgaReportForm" (ngSubmit)="onSubmit()">
<div formArrayName="answerDetails">
  <!-- <div *ngFor="let vg of AnswerDetails.controls; let i=index"> -->
    <div [formGroupName]="i">
      <table class="table table-striped table-bordered table-hover dataTable">
        <thead>
          <tr class="thead">
            <th style="width: 25%">Zone of the Sphere</th>
            <th style="width: 25%">Strategic Intent</th>
          </tr>
          <tr>
            <td>Core</td>
            <td> <input type="text" class="form-control" formControlName="core"> </td>
          </tr>
          <tr>
            <td>Vital Interests</td>
            <td> <input type="text" class="form-control" formControlName="vitalInterests"> </td>
          </tr>
          <tr>
            <td>Buffer Zones</td>
            <td> <input type="text" class="form-control" formControlName="bufferZones"> </td>
          </tr>
          <tr>
            <td>Pivotal Zones</td>
            <td> <input type="text" class="form-control" formControlName="pivotalZones"> </td>
          </tr>
          <tr>
            <td>Forward Positions</td>
            <td> <input type="text" class="form-control" formControlName="forwardPositions"> </td>
          </tr>
          <tr>
            <td>Power Vacuums</td>
            <td> <input type="text" class="form-control" formControlName="powerVaccums"> </td>
          </tr>
        </thead>
    </table>
 </div>
 </div>
 </form>

When I ran this code it throws an error like,

Cannot find control with path: 'answerDetails -> -> core', Cannot find control with path: 'answerDetails -> -> vitalInterests', Cannot find control with path: 'answerDetails -> -> forwardPositions' and more

Please help me to find a solution.

1
  • <!-- <div *ngFor="let vg of AnswerDetails.controls; let i=index"> --> you are using i but this line is commented. Uncommenting doesn't fix? Commented Sep 2, 2021 at 13:23

1 Answer 1

0

you should use this code in html maybe it helps

formArrayName="AnswerDetails" *ngFor="let item of fg.get('AnswerDetails')['controls']; 
Sign up to request clarification or add additional context in comments.

1 Comment

can u please show some screenshot or anything so i can help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.