My Angular 6 application has a form with the following example code:
export class SampleComponent implements OnInit {
form: FormGroup;
constructor(private fb: FormBuilder) { }
ngOnInit() {
this.form = new FormGroup({
first: new FormControl(),
last: new FormControl()
});
this.markControlsAsDirty(this.form);
}
markControlsAsDirty(form: FormGroup) {
this.form.get('first').markAsDirty();
this.form.get('last').markAsDirty();
}
}
I am looking for a way to mark all controls in a form group as dirty, rather than having to individually mark each one.
UPDATE: I have added a Stackblitz example to demonstrate that previous answers were incorrect.