Created
September 20, 2017 12:38
-
-
Save elcodabra/df79ddd160f2a995ac4db9cfabdcda7b to your computer and use it in GitHub Desktop.
Adding Validation for Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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