Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

491
Views
Dynamic form is not working while using ng-container and ng-template

I am creating a dynamic form where I am getting the form fields form api. I am using ng-container & ng-template to reuse the formgroup multiple times but it's not working as expected. When I am using usual div it's working as expected.

https://stackblitz.com/edit/angular-ivy-hqc49t

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use FormGroup instances instead of formGroupName, because template loses context of formGroup: Stackblitz

<ng-container
    *ngTemplateOutlet="
      fieldsTemplate;
      context: {
        formGroup: formGroundUse.get('groundUses')
      }
    "
  >
  </ng-container>
<div formArrayName="groundUsesArray">
groundUsesArray
<ng-container *ngFor="let data of groudUse.controls">
  <ng-container
    *ngTemplateOutlet="
      fieldsTemplate;
      context: {
        formGroup: data
      }
    "
  >
  </ng-container>
</ng-container>
<ng-template #fieldsTemplate let-formGroup="formGroup">
  <div [formGroup]="formGroup">
    <tr>
      <td class="input-container">
        <label for="">title</label>
        <input type="text" class="form-input" formControlName="title" />
      </td>
      <td class="input-container">
        <label for="">value</label>
        <input type="text" class="form-input" formControlName="value" />
      </td>
      <td class="input-container">
        <label for="">percentage</label>
        <input type="number" class="form-input" formControlName="percentage" />
      </td>
    </tr></div
></ng-template>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!