Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

angular initail valeur in fromgroup

we are creating FormGroup as following.
userForm = new FormGroup({
     name: new FormControl(),
     age: new FormControl()
}); 

1. Using setValue()
this.userForm.setValue({name: 'Mahesh', age: '20' }); 
It is necessary to mention all from controls in setValue() otherwise it will throw error.
2. Using patchValue()
this.userForm.patchValue({name: 'Mahesh'}); 
When we use patchValue() then it is not necessary to mention all form controls.
 
PREVIOUS NEXT
Tagged: #angular #initail #valeur #fromgroup
ADD COMMENT
Topic
Name
1+3 =