How to check the innerformgroup status im angular reactive form

How to check the innerformgroup status im angular reactive form



I have a formgroup named as productForm and inner formgroupName productInnerForm.i can able to see outer form group status and value.
by using below markup



when i have tried with innerformgroup status getting error.


<pre> json</pre>
<pre> json</pre>



In component also getting undefined.
this.productForm.get('productInnerForm').valid which shows undefined.


this.productForm.get('productInnerForm').valid



outer form status is working as expected.


this.productForm.valid;



in component.ts


constructor(public formBuilder : FormBuilder)



productForm:FormGroup;


this.productForm= this.formBuilder.group(
ProductIDCtrl: '',
productInnerForm: this.formBuilder.group(
ProductNameCtrl:[''],
ProductSUKCtrl:[''],
ProductStatusCtrl:[''],
ProductTypeCtrl:['']

)
);

--------------------------------

<form [formGroup]="productForm" class="secondary-search">

<input type="text" formControlName="ProductIDCtrl">


<div formGroupName="productInnerForm">
<input type="text" formControlName="ProductNameCtrl">
<input type="text" formControlName="ProductSUKCtrl">

<input type="text" formControlName="ProductStatusCtrl">
<input type="text" formControlName= "ProductTypeCtrl">
</div>

//For Checking whole form

<pre> json</pre>
<pre> json</pre>


How to check the inner form group status .

<pre> json</pre>
<pre> json</pre>



In component howw to check that

this.productForm.get('productInnerForm').valid which shows undefined





Could you share your code in stackblitz ?
– shohrukh
Aug 30 at 7:53





this is a demo stackblitz of sample stackblitz.com/edit/…
– Mohamed Sahir
Aug 30 at 20:10




1 Answer
1



You can create a getter method for your inner form group:


get productInnerForm(): FormGroup
return this.productForm.get('productInnerForm') as FormGroup;



And then use it in your component class or the template:



In the class component: console.log(this.productInnerForm.value);


console.log(this.productInnerForm.value);



In the template: json or json etc.


json


json



You can also get access to the inner form group without use get('...') method:


get('...')



this.productForm.controls['productInnerForm'].value or this.productForm.controls['productInnerForm'].status etc.


this.productForm.controls['productInnerForm'].value


this.productForm.controls['productInnerForm'].status



I've forked your sb example and added this example, check it out.





Thank you for the valuable comments, could you please explain why we need get accessor here
– Mohamed Sahir
Aug 31 at 13:50





In angular FormGroup class inherits from AbstractControl class, which has a method get - it simply retrieves a child form group or control given the control's name. You can check official docs on for more details on this.
– shohrukh
Aug 31 at 13:56


FormGroup


AbstractControl


get



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

Node.js puppeteer - Use values from array in a loop to cycle through pages