can we create more formgroup in angular code example
Example 1: formgroup addcontrol
let form: FormGroup = new FormGroup({});
form.addControl(field_name, new FormControl('', Validators.required));
Example 2: formbuilder multiple groups
export class FormBuilderComp {
addUserFrom: FormGroup;
constructor( @Inject(FormBuilder) fb: FormBuilder) {
this.addUserFrom = fb.group({
userGroup: fb.group({
name: ['', Validators.required],
email: ['', Validators.required],
phone: ['', Validators.required]
}),
addressGroup: fb.group({
street: ['', Validators.required],
suite: ['', Validators.required],
city: ['', Validators.required],
zipCode: ['', Validators.required]
})
});
}
}