title: Angular FormArray patchValue error: TypeError: value.forEach is not a function - how to resolve?
body: <p>Page was originally written as a template driven form, but is being converted to reactive in order to add auto-save feature.</p>
  
  <p>In the page component's constructor I define the reactive form variable:</p>
  
  <pre><code> this.form = fb.group({
      reviewer: '',
      position: '',
      officeName: '',
      rows: fb.array([]),
      comments1: '',
      comments2: '',
      comments3: ''
  });
  </code></pre>
  
  <p>'rows' is the field relevant to this issue.</p>
  
  <p>In the ngInit a request is made, through a web api, to retrieve persisted form data. The data is retrieved as an array of rows, each containing an array of 6 cells. The third cell will be tied to a FormControl, the others will be rendered as static text.</p>
  
  <pre><code>this.rows = summaryReportQuestion.map(summaryReportQuestionObj =&gt; {
      return {
          cells: [
              summaryReportQuestionObj.questionID,
              summaryReportQuestionObj.question,
              (summaryReportQuestionObj.columnSign == '$' ? (summaryReportQuestionObj.columnSign + ' ' + summaryReportQuestionObj.target) : summaryReportQuestionObj.target + ' ' + summaryReportQuestionObj.columnSign),
              (summaryReportQuestionObj.budget == null ? summaryReportQuestionObj.budget : (summaryReportQuestionObj.columnSign == '$' ? summaryReportQuestionObj.columnSign + ' ' + this.utilityService.formatNumberWithCommas(Math.floor(summaryReportQuestionObj.budget), false) : summaryReportQuestionObj.budget + ' ' + summaryReportQuestionObj.columnSign)),
              (summaryReportQuestionObj.average == null ? summaryReportQuestionObj.average : (summaryReportQuestionObj.columnSign == '$' ? summaryReportQuestionObj.columnSign + ' ' + this.utilityService.formatNumberWithCommas(Math.floor(summaryReportQuestionObj.average), false) : summaryReportQuestionObj.average + ' ' + summaryReportQuestionObj.columnSign)),
              (summaryReportQuestionObj.top20Percent == null ? summaryReportQuestionObj.top20Percent : (summaryReportQuestionObj.columnSign == '$' ? summaryReportQuestionObj.columnSign + ' ' + this.utilityService.formatNumberWithCommas(Math.floor(summaryReportQuestionObj.top20Percent), false) : summaryReportQuestionObj.top20Percent + ' ' + summaryReportQuestionObj.columnSign))
          ]
      };
  });
  
  let faRows = new FormArray([]);
  for (var i = 0, len = this.rows.length; i &lt; len; i++) {
      let row = this.rows[i].cells;
      for (var j = 0, length = this.rows[i].cells.length; j &lt; length; j++) {
          let fc = new FormControl(this.rows[i].cells[j]);
          faRows.push(fc);
      }
  }
  
  // this.form.setValue({rows: faRows});
  // this.form.setControl('rows', faRows);
  </code></pre>
  
  <p>In the html:</p>
  
  <pre><code>&lt;tbody&gt;
      &lt;tr *ngFor="let row of rows;let r = index" [attr.data-index]="r"&gt;
          &lt;ng-container&gt;
              &lt;td *ngFor="let cell of row.cells;let i = index" [attr.data-index]="i"&gt;
                  &lt;span *ngIf="i != 2"&gt;{{cell}}&lt;/span&gt;
                  &lt;!-- &lt;input type="text" formControlName="form.rows[r]" *ngIf="i == 2"&gt; --&gt;
              &lt;/td&gt;
          &lt;/ng-container&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p>Based on a comment and an answer I've clarified my intention and code. 
  [thank you @amal and @DeborahK] 
  I am now only tying one cell of data from each row to a FormControl, with the other cells in each row displayed with:
   {{cell}} </p>
  
  <p>Therefore I need to render the contents of this.rows (as shown in html) as well as this.form.rows. </p>
  
  <p>I am currently having two problems understanding how to accomplish this. In the typescript, leaving the final block of loops iterating over the rows of data that create the rows' FormControls the array faRows contains precisely what I expect, a FormArray of FormControls, and each has retrieved it's correct associated saved value. But when attempting to copy data from this.rows to create the FormControls for form.rows, I'm not able to get either setValue or setControl to work correctly. This may be related to the naming of the FormControl on the html page, which is my second issue.</p>
  
  <p>I'm not clear on how to reference the form variable to dynamically create the formControlName in html. This is what I imagine, but it doesn't work.</p>
  
  <pre><code> &lt;input type="text" formControlName="form.rows[r]" *ngIf="i == 2"&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Jzrea.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Jzrea.png" alt="Page rendered as template driven form"></a></p>