Reputation: 89
While creating a reactive forms in angular we why we need to use formBuilder instead of FormGroup when we can make reactive forms using either of them.
Here i also provided what i am trying to ask
maintenanceForm: FormGroup;
ngOnInit() {
this.maintenanceForm = new FormGroup({
'value': new FormControl(null),
'dropdown': new FormControl(null)
})
}
/* Here As we can make reactive forms in this two ways but when to use either of them */
this.maintenanceForm = this.formBuilder.group({
body_type_id: ['', Validators.required],
make_name: ['', Validators.required]
});
Upvotes: 3
Views: 3245
Reputation: 232
Form my experience, using FormBuilder reduces the syntax to be written especially when you have very large and complex forms. Please see below links,
https://angular.io/api/forms/FormBuilder https://angular.io/api/forms/FormGroup
This link shows the syntactic difference between using both approaches https://angular.io/guide/reactive-forms
Upvotes: 1