angular formgroup mark as touched

Solutions on MaxInterview for angular formgroup mark as touched by the best coders in the world

showing results for - "angular formgroup mark as touched"
Maximilien
07 Jul 2016
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}