Created
February 28, 2019 01:51
-
-
Save camilogiraldo/948028988c0c09e0309900f6662651f7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 [formGroup]="form" (submit)="submitForm()"> | |
<ng-template ngFor let-input [ngForOf]="formData"> | |
<ng-container [ngSwitch]="input.controlType"> | |
<!-- handling text type inputs --> | |
<ng-template [ngSwitchCase]="'text'"> | |
<div class="form-group"> | |
<label [for]="input.controlName"> {{input.controlName}}</label> | |
<input [formControlName]="input.controlName" [type]="input.valueType" [name]="input.controlName" | |
[required]="input.validators.required" [minlength]="input.validators.minlength" | |
[maxlength]="input.validators.maxlength" /> | |
<div class="error" *ngIf="form.get(input.controlName).invalid && | |
(form.get(input.controlName).dirty || form.get(input.controlName).touched)"> | |
<div *ngIf="form.get(input.controlName).errors.required">Input required</div> | |
<div *ngIf="form.get(input.controlName).errors.minlength">Minimum length is {{input.validators.minlength}}</div> | |
</div> | |
</div> | |
</ng-template> | |
</ng-container> | |
</ng-template> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment