template driven forms validation for touched and pristin code example

Example 1: ngForm

<form #f="ngForm" (ngSubmit)="onSubmit(f)" novalidate>
  <input name="first" ngModel required #first="ngModel">
  <input name="last" ngModel>
  <button>Submit</button>
</form>

<p>First name value: {{ first.value }}</p>
<p>First name valid: {{ first.valid }}</p>
<p>Form value: {{ f.value | json }}</p>
<p>Form valid: {{ f.valid }}</p>

Example 2: formgroup check if valid

form: FormGroup;

onSubmit(){
    //checks if form is valid
       if( this.form.valid){
          //more code here
        }
}