title: How to add dynamically generated form group to dynamically generated table rows in Angular?
body: <p>I have an Angular application that has a questionnaire table that's dynamically generated, with X amount of subjects for whom the user has to answer questions about. What makes this tricky is that the rows correspond to the questions and the columns correspond to the answers (this is a mandate that I can't alter), so I can't wrap the generated rows in a form group that completely takes care of the answers for each individual subject. HTML looks like:</p>
  <pre><code>  &lt;tr *ngFor=&quot;let question of questions; index as i&quot;&gt;
        &lt;td class=&quot;question-column&quot;&gt;{{ question }}&lt;/td&gt;
        &lt;td *ngFor=&quot;let name of networkNames&quot;&gt;
          &lt;app-value-dropdown
            [name]=&quot;name&quot;
            [parent]=&quot;answers&quot;
            [question]=&quot;question&quot;
          &gt;&lt;/app-value-dropdown&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
  </code></pre>
  <p>The furthest I've gotten is to dynamically create a FormArray of FormGroups that models the structure of the table as far as containing form controls that correspond appropriately, like so:</p>
  <pre><code> buildForm() {
      const questions = Object.keys(this.questionFields);
      questions.forEach(question =&gt; {
        const group = new FormGroup({});
        this.networkNames.forEach(name =&gt; {
          group.addControl(
            `${name}__${question}`,
            new FormControl(0, Validators.required)
          );
        });
        this.answers.push(group);
      });
    }
  </code></pre>
  <p>The problem I'm running into is attaching the corresponding FormGroup to each row as it's generated; I've tried taking advantage of the index on the table row and wrapping the inside of the <code>&lt;tr&gt;</code> in a form with the [formGroup] set to the current FormGroup on that iteration, but it causes the rows to not render. How can I adjust this code/approach to get the form set up as needed?</p>