Reputation: 125
I have Nested Form Groups
address = new FormGroup({
'com.complex.Address':new FormGroup({
city: cityControl,
streetName: streetNameControl,
houseNumberAddition: houseNumberAdditionControl,
houseNumber: houseNumberControl,
postcode: postcodeControl
})
});
I want to find the nested form group i.e. "com.complex.Address".
I have already tried
this.form.get('address').get('com.complex.Address');
But it always return Null value.
Now If I change the nested formgroup (i.e. 'com.complex.Address') to any other name like "test" and execute this.form.get('address').get('test');
it actually return the value which i want.
But the point is I can not change the nested name and it will contain some of the special character in it.
How can i escape the character and use the form group as i want.?
Upvotes: 2
Views: 4634
Reputation: 2556
Looking at the angular code of the .get() it use "." as delimiter to make an array of paths.
I can't see any solution to pass trought it. Anyway you could use :
(<FormGroup>this.form.get('address')).controls['com.complex.Address'];
Upvotes: 4
Reputation: 199
try like this
NewForm = this.fb.group({
relationshipId: this.fb.group({
code: [null, Validators.required]
})});
this.NewForm.get('relationshipId').value.code
this.NewForm.get('relationshipId').get('code').value`
Upvotes: 0