Skip to content

Instantly share code, notes, and snippets.

@wpflames
Created June 27, 2022 12:07
Show Gist options
  • Select an option

  • Save wpflames/5ad56f2107b773bbc5ffac5ba6ac1b85 to your computer and use it in GitHub Desktop.

Select an option

Save wpflames/5ad56f2107b773bbc5ffac5ba6ac1b85 to your computer and use it in GitHub Desktop.
Form validation
<h2>Leave a comment</h2>
<form>
<div class="form-group">
<label for="firstName">First Name</label>
<input
ngModel
name="firstName"
#firstName="ngModel"
(change)="log(firstName)"
type="text"
id="firstName"
required
class="form-control">
<div
*ngIf="!firstName.valid && firstName.touched"
class="alert alert-danger"
>First Name is required</div>
</div>
<div class="form-group">
<label for="comment">Comment</label>
<textarea
ngModel
name="comment"
id="comment"
cols="30"
rows="10"
class="form-control">
</textarea>
</div>
<button class="btn btn-dark">Submit</button>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment