2

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.?

2 Answers 2

4

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']; 
Sign up to request clarification or add additional context in comments.

3 Comments

I already tried it but it shows an error "Property 'controls' does not exist on type 'AbstractControl'."
Ok see the edited answer. It's was just a type problem. You must specifity that you are sure that you will get a FormGroup
Yes It Solves the problem Thank You.
0

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`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.