1
2// From Angular 8/9 you can simply use
3this.formGroup.markAllAsTouched();
4
5
6/**
7 * For version older than Angular 8
8 * Marks all controls in a form group as touched
9 * @param formGroup - The form group to touch
10 */
11private markFormGroupTouched(formGroup: FormGroup) {
12 (<any>Object).values(formGroup.controls).forEach(control => {
13 control.markAsTouched();
14
15 if (control.controls) {
16 this.markFormGroupTouched(control);
17 }
18 });
19}