I am trying to do validation using the
and
. This works fine when user tabs out of the input without filling. B
the easiest way is call markUserNameTouched() method as below on button click on template. We use markAsTouched() on formControl.
public staffLoginForm: FormGroup;
ngOnInit(){
this.staffLoginForm = new FormGroup({
username: new FormControl(null),
password: new FormControl(null)});
markUserNameTouched():void{
this.staffLoginForm.get('username').markAsTouched();
}