Wednesday, July 12, 2017

Use .patchValue with a FormGroup in Angular 2!

This is a way to add setup values to a FormGroup after you've set it up. They could come from data loaded from a service. In the example below I'm just jamming them in.

this.myFormGroup.patchValue({
   'Yin': "Vicky",
   'Yang': "Christina"
});

 
 

This will put "Vicky" in the Yin control and "Christina" in the Yang control and it doesn't really matter where in the FormControl Yin and Yang are. They seem to get found even if they are nested in a FromGroup within the FormGroup.

No comments:

Post a Comment