I am trying to do validation using the
and
. This works fine when user tabs out of the input without filling. B
I am providing 3 different solutions for different scenarios, use the one which suits you.
If you are using a form, then do
this.form.markAllAsTouched();
If you need a particular field to be affected inside form, then filter that nameControl and do
nameControl.markAsTouched();
If you are not using forms, then specify a ref
for the input
element and initialize variable in ts file & do as follows,
@ViewChild('myInputRef') myInputRef; // Initialize the ref of input element
.
.
this.myInputRef.control.markAsTouched()