I am trying to do validation using the
and
. This works fine when user tabs out of the input without filling. B
Since you want to show mat error on button's click, please try the below: For Angular6 version:
1). import below:
import { FormControl, FormBuilder, FormGroup } from '@angular/forms';
2). declare form control in .ts file:
nameControl = new FormControl('');
3). put control in html:
name is required
3). on button's click:
this.nameControl.markAsTouched();
It's important to check how you are using the form control, ".markAsTouched()" on point 3 will show the mat error for the corresponding form control.