title: (Angular 5) Error: Cannot read property 'setValue' of undefined
body: <p>I'm initializing my form this way, but when I need to edit it, it does not accept the values</p>
  
  <p>component.ts</p>
  
  <pre><code>ngOnInit() {
    this.tinvoiceService.initForm();
  }
  </code></pre>
  
  <p>tinvoice.service.ts</p>
  
  <pre><code>form: FormGroup;
  
  constructor(
    private _fb: FormBuilder, 
    private invoiceService: InvoiceService
  ) {}
  
  initForm(): void {
    this.form = this._fb.group({
      customer: [null, Validators.required],
      totalPrice: 0,
      purchases: this._fb.array([])
    });
  
    // initialize stream
    const myFormValueChanges$ = this.form.controls['purchases'].valueChanges;
    myFormValueChanges$.subscribe(purchases =&gt; this.updatePurchasesAmount(purchases));
  
  }
  </code></pre>
  
  <p>from the HTML I pass the values</p>
  
  <p>tinvoice.component.html</p>
  
  <pre><code>&lt;a 
    class="btn btn-outline-info text-info" 
    (click)="tinvoiceService.populateForm(invoice)"&gt;
    Edit
  &lt;/a&gt;
  </code></pre>
  
  <p>tinvoice-list.component.ts</p>
  
  <pre><code>populateForm(invoice) {
    this.form.setValue(invoice);  
  }
  </code></pre>
  
  <p>by console I have this result</p>
  
  <p><a href="https://i.stack.imgur.com/P1j0m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P1j0m.png" alt="enter image description here"></a></p>
  
  <p><a href="https://stackblitz.com/edit/invoice-stackoverflow" rel="nofollow noreferrer">View in StackBlitz</a></p>
  
  <p>any ideas?</p>