title: ERROR TypeError: Cannot read property 'forEach' of undefined
body: <p>Im working on a project that I want to display and edit a array. My problem is 'Cannot read property 'forEach' of undefined' I don't understand why.</p>
  
  <p>My component.html</p>
  
  <pre><code>&lt;form [formGroup]="editHomeboxPForm" (ngSubmit)="onEditHomeboxP()" class="col s12" materialize&gt;
  
             &lt;div class="row"&gt;
                 &lt;div class="input-field col s10"&gt;
                   &lt;div formArrayName="sensors_id"&gt;
                     &lt;div class="form-group" *ngFor="let sensor of editHomeboxPForm.get('sensors_id').value; let i = index"&gt;
                       &lt;br&gt;
                       &lt;select formControlName="{{i}}" id="sensors_id" materialize="material_select"
       [materializeSelectOptions]="homeboxp.sensors" [ngClass]="{invalid:
       invalidinput}"&gt;
                         &lt;option value="" disabled selected&gt;Select Sensor&lt;/option&gt;
                         &lt;option *ngFor="let sensor of homeboxp.sensors" [value]="sensor.sensors_id"&gt;{{sensor.sensor_serial}}&lt;/option&gt;
                       &lt;/select&gt;
                       &lt;div class="button-left"&gt;
                         &lt;button *ngIf="editHomeboxPForm.controls.sensors_id.value.length &gt; 1" type="button" class="fa"
       (click)="onRemoveItem(i)"&gt;RemoveSensor&lt;/button&gt;
                       &lt;/div&gt;
                     &lt;/div&gt;
                   &lt;/div&gt;
  
                 &lt;/div&gt;
                 &lt;div class="input-field col s2"&gt;
                 &lt;button type="button" class="btn" (click)="onAddItem()"&gt;AddSensor&lt;/button&gt;
                 &lt;/div&gt;
            &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Component.ts</p>
  
  <pre><code>  editHomeboxPForm: FormGroup;
    homeboxp: HomeboxP;
  
    constructor(private hps: HomeboxpackageService,
      private router: Router,
      private fb: FormBuilder,
      private activatedRoute: ActivatedRoute) {
  
        this.editHomeboxPForm = new FormGroup({
        'serial_number': new FormControl('', [Validators.required, Validators.nullValidator]),
        'sensors_id': this.fb.array([]) 
      });
    }
  
    ngOnInit() {
      this.populateFormHomeboxP();
  
    }
    ngAfterViewChecked() {
  
      Materialize.updateTextFields();
    }
    populateFormHomeboxP() {
      this.activatedRoute.params.subscribe(
        params =&gt; {
          this.hps.getHomeboxPById(params['id']).subscribe(
            homeboxp =&gt; {
              this.homeboxp = homeboxp;
              this.editHomeboxPForm.controls['serial_number'].setValue(homeboxp.serial_number);
              this.editHomeboxPForm.controls['sensors_id'].setValue(homeboxp.sensors_id); // at SafeSubscriber.eval [as _next]
             }
          );
        }
      );
    }
    onEditHomeboxP() {
      this.loading = true;
      let editHomeboxP = new HomeboxP(
        this.editHomeboxPForm.value
      );
      editHomeboxP.homebox_id = this.homeboxp.homebox_id;
      this.hps.UpdateHomeboxp(editHomeboxP).subscribe(
        result =&gt; {
          if (result === true) {
            Materialize.toast('successfully', 4000);
                   } else {
            this.loading = false;
          }
        },
        error =&gt; {
          this.loading = false;
        }
      );
    }
    onAddItem() {
      (&lt;FormArray&gt;this.editHomeboxPForm.controls['sensors_id']).push(new FormControl('', Validators.required));
     }
     onRemoveItem(index: number) {
      (&lt;FormArray&gt;this.editHomeboxPForm.controls['sensors_id']).removeAt(index);
   }
  </code></pre>
  
  <p>Can you suggest me, how is the problem. In console: ERROR TypeError: Cannot read property 'forEach' of undefined. Also in console display all json. Like this:</p>
  
  <blockquote>
    <p>{"StatusCode":0,"StatusMessage":"OK","StatusDescription":{ "sensors":
    [ {"sensor_serial":"SensorSerial1", "sensors_id":"11E807676E3F30B5"},
    {"sensor_serial":"sensorserial2", "sensors_id":"11E807679D82841L"},
    {"sensor_serial":"sensorserial3", "sensors_id":"11E80767A5CD2820"} ]
    ,"homeboxpackage_id":"11E80768K", "active":0,
    "homebox_id":"11E8076792BD0164J",
    "date_created":"2018-02-01T15:55:54.000Z", "date_modified":null,
    "serial_number":"serialn1", "user_id":"3"} }</p>
  </blockquote>