multiple form groups angular code example
Example 1: 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]
})
});
}
}
Example 2: accessing formcontrol from fromgroup
this.myForm.controls["key"]
(or)
this.myForm.get("key")