Skip to content

Instantly share code, notes, and snippets.

@ngohungphuc
Created March 7, 2019 14:29
Show Gist options
  • Save ngohungphuc/d758809a3498f473cc75dbf1bb87f7c8 to your computer and use it in GitHub Desktop.
Save ngohungphuc/d758809a3498f473cc75dbf1bb87f7c8 to your computer and use it in GitHub Desktop.
<form [formGroup]="myForm">
<div>
<input type="text" class="form-input" [ngModel]="name" formControlName="name" />
</div>
<label class="form-group err-msg" *ngIf="myForm.get('name').hasError('required') && (name.get('name').dirty || myForm.get('name').touched)">Name is required</label>
<label class="form-group err-msg" *ngIf="myForm.get('name').hasError('whitespaces') && (name.get('name').dirty || myForm.get('name').touched)">Name is required</label>
<div>
<input type="text" class="form-input" [ngModel]="email" formControlName="email" />
</div>
<label class="form-group err-msg" *ngIf="myForm.get('email').hasError('required') && (myForm.get('email').dirty || myForm.get('email').touched)">Email
is required</label>
<button type="submit" disabled="!myForm.valid">Submit</button>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment