, - Angular .
. , - (, , , submit, , , ).
:
onSubmit() {
if (this.form.valid) {
console.log('form submitted');
} else {
this.validateAllFormFields(this.form);
};
}
validateAllFormFields(formGroup: FormGroup) {
Object.keys(formGroup.controls).forEach(field => {
const control = formGroup.get(field);
if (control instanceof FormControl) {
control.markAsTouched({ onlySelf: true });
} else if (control instanceof FormGroup) {
this.validateAllFormFields(control);
}
});
}
.