Loop through all form controls in formgroup in reactive form

preview_player
Показать описание
In this video we will discuss, how to loop through all form controls in a formgroup including nested form groups in a reactive form.

Healthy diet is very important for both body and mind. We want to inspire you to cook and eat healthy. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking.

Text version of the video

Slides

Angular 6 Tutorial

Angular 6 Tutorial Text Articles & Slides

Angular, JavaScript, jQuery, Dot Net & SQL Playlists

Understanding this technique is very useful, as it can help us perform the following on all the form controls in a reactive form
1. Reset form controls

2. Enable or disable all form controls or just the nested formgroup controls

3. Set validators and clear validators

4. Mark form controls as dirty, touched, untouched, pristine etc.

5. Move validation messages and the logic to show and hide them into the component class from the view template.

Here is what we want to do : Loop through each form control in a form group including nested form groups and log the form control key and value to the console.

logKeyValuePairs(group: FormGroup): void {
// loop through each key in the FormGroup
// If the control is an instance of FormGroup i.e a nested FormGroup
// then recursively call this same method (logKeyValuePairs) passing it
// the FormGroup so we can get to the form controls in it
if (abstractControl instanceof FormGroup) {
// If the control is not a FormGroup then we know it's a FormControl
} else {
}
});
}
Рекомендации по теме
Комментарии
Автор

Thank you very much Venkat Sir, You are the best teacher I have never seen such explanation anywhere on youtube.

harrymaan
Автор

Perfect! after googling for 15 mins which got me nowhere this is what I wanted. Thank you.

Lukex
Автор

Best explanation ever. Thank you so much Sir!!!

gomathirr
Автор

Really your content is phenomenal, essential content is there, it really helpful. You are one of the very instructor as like as foreign instructor, thank you so much, simplest but effective

nezensamuel
Автор

Great Video. If I was doing a post what is the best practice to saving multiple nest form group values. Thanks !!!!

trustingod
Автор

Hi!!!
do you have your code uploaded on github
or somewhere else???

oudarjyasensarma
Автор

Thank you for your efforts made making these videos

rahulkamboj
Автор

Please can anyone tell if we log the abstractControl. What would be the result in all the cases i am bit confused please reply and tell me the answer thanks

nerallaraviteja
Автор

Completely enjoy your videos. Thank you. I cannot get the logKeyValuePairs(group: FormGroup).... to work. the error message says the group is shadow name, no shadow variable and all I get is errors.

terrymcbride
Автор

logically build and very useful, thanks.

hbela