src/app/shared/components/form-error/form-error.component.ts
selector | crm-form-error |
styleUrls | form-error.component.scss |
templateUrl | ./form-error.component.html |
Inputs |
constructor()
|
control
|
Type: |
errors
|
Type:
Default value: |
import {Component, Input} from '@angular/core';
import {FormControl} from "@angular/forms";
@Component({
selector: 'crm-form-error',
templateUrl: './form-error.component.html',
styleUrls: ['./form-error.component.scss']
})
export class FormErrorComponent {
@Input() control: FormControl;
@Input() errors: {name: string, message: string}[] = [];
constructor() { }
}
<div class="form-error" *ngIf="control && !control.valid && (control.dirty || control.touched)">
<div *ngFor="let error of errors">
<span *ngIf="control.hasError(error.name)">{{error.message}} </span>
</div>
</div>