Skip to content

Instantly share code, notes, and snippets.

@shadow1349
Created February 24, 2023 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shadow1349/d92304e8df59cb360058270111cc052e to your computer and use it in GitHub Desktop.
Save shadow1349/d92304e8df59cb360058270111cc052e to your computer and use it in GitHub Desktop.
<form #myForm="ngForm" (ngSubmit)="onSubmit()">
<div ngModelGroup="user">
<label>
Name:
<input type="text" name="name" [(ngModel)]="name" required>
</label>
<div *ngIf="myForm.controls['user']?.controls['name'].invalid && myForm.controls['user']?.controls['name'].touched">
<div *ngIf="myForm.controls['user']?.controls['name'].errors.required">Name is required</div>
</div>
</div>
<button type="submit">Submit</button>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment