Skip to content

Instantly share code, notes, and snippets.

@elcodabra
Created September 20, 2017 12:38
Show Gist options
  • Save elcodabra/df79ddd160f2a995ac4db9cfabdcda7b to your computer and use it in GitHub Desktop.
Save elcodabra/df79ddd160f2a995ac4db9cfabdcda7b to your computer and use it in GitHub Desktop.
Adding Validation for Angular
<form #regForm="ngForm" (ngSubmit)="onAdd()">
<div class="form-group">
<textarea
type="text" name="content"
required
[ngClass]="{'form-control':true,'is-invalid':!regForm.form.valid && regForm.form.touched}"
placeholder={{placeholder}}
[(ngModel)]="model.content">
</textarea>
<div class="invalid-feedback" *ngIf="!regForm.form.valid && regForm.form.touched">
Field is required
</div>
</div>
<button type="submit" class="btn btn-primary" [disabled]="!regForm.form.valid">Submit</button>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment