Monday, February 19, 2018

You may find you cannot dot dot dot out to stuff at a FormGroup in an Angular 4 app and that you instead must use the square bracket means of fishing for a property.

In a FormGroup called presidentsForm I made lineItems like so:

this.presidentsForm = new FormGroup({
   'lineItems': presidents
});

 
 

lineItems, my own invention, is naturally not going to be undersood by the TypeScript compiler, so while I can get away with something like this in a component template:

*ngFor="let lineItem of presidentsForm.get('lineItems').controls; let i=index"

 
 

...at the .ts file for the component itself I have to do something like this:

datum.Name = this.presidentsForm
      .controls['lineItems']['controls'][counter]['controls']['name'].value;

No comments:

Post a Comment