angular-custom-validators

Angular custom validator apply template for repetitive code

╄→гoц情女王★ 提交于 2021-01-29 11:27:18
问题 I have multiple input fields where almost same validation is required. Is there any way to reduce repetitive HTML code for displaying error. My code is as below <div colspan="2"> <input type="text" name="appName" [disabled]="recordCreated" [(ngModel)]="appName" appForbiddenName="Application" minlength="4" required #name="ngModel" [ngClass]="{'has-danger': name.invalid && (name.dirty || name.touched) }" /> <div *ngIf="name.invalid && (name.dirty || name.touched)" class="alert alert-danger">

Angular Forms: How to avoid multiple NgIf divs for validation error messages?

你。 提交于 2021-01-27 16:01:44
问题 I would like to simplify the code below: <div *ngIf="form1.errors?.checkDate && (form1.touched || form1.dirty)" class="cross-validation-error-message alert alert-danger"> Date can't be in the future. </div> <div *ngIf="form1.errors?.notAfterDate && (form1.touched || form1.dirty)" class="cross-validation-error-message alert alert-danger"> Birth Date must be after 1/1/1800. </div> It should have only 1 div *ngif and pass the error message as a value instead of hardcoding or use a ngFor ? Any

Angular Forms: How to avoid multiple NgIf divs for validation error messages?

会有一股神秘感。 提交于 2021-01-27 15:56:17
问题 I would like to simplify the code below: <div *ngIf="form1.errors?.checkDate && (form1.touched || form1.dirty)" class="cross-validation-error-message alert alert-danger"> Date can't be in the future. </div> <div *ngIf="form1.errors?.notAfterDate && (form1.touched || form1.dirty)" class="cross-validation-error-message alert alert-danger"> Birth Date must be after 1/1/1800. </div> It should have only 1 div *ngif and pass the error message as a value instead of hardcoding or use a ngFor ? Any