Updating our component form model – using setValue and patchValue

First off, let's have a little reminder of how we can create a form programmatically. We used to use the dictionary variable and pass that to the FormGroup constructor, but we may as well skip that variable and define the dictionary inline, as in the following code:

const form = new FormGroup({
name: new FormControl(''),
surname: new FormControl(''),
age: new FormControl
})

To change any of the values in the form, we can use one of two approaches:

  • setValue(), which will replace all values
  • patchValue(), which will only update the mentioned controls
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset