Prefill form
Prefill form
Section titled “Prefill form”Note
setValue()
sets all form control values at once and requires you to provide values for every form control - if you miss any, it throws an error.
patchValue()
updates some or all form controls and ignores missing properties - it only updates the controls that match.
Use setValue()
to completely replace all form values, use patchValue() for partial updates.
Instructions
Section titled “Instructions”-
Update the
TaskForm
class:task.form.ts preFillForm() {this.form.setValue({title: 'Generated Task',description: 'Generated Description',});}
Note
With setValue()
if you miss any, it throws an error. Use it when you want to completely replace all form values.