Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 3x 3x 3x 5x 8x 4x 4x 1x 3x 3x 3x | import { ChangeDetectionStrategy, Component, DoCheck, Input } from '@angular/core';
import { AbstractControl } from '@angular/forms';
interface FormErrorMessages {
[key: string]: string;
}
@Component({
selector: 'ish-form-control-feedback',
templateUrl: './form-control-feedback.component.html',
changeDetection: ChangeDetectionStrategy.Default,
})
export class FormControlFeedbackComponent implements DoCheck {
@Input({ required: true }) control: AbstractControl;
@Input() messages: FormErrorMessages = {};
errors: string[];
ngDoCheck() {
if (this.control.dirty) {
this.errors = this.getErrorList();
}
}
private getErrorList(): string[] {
if (!this.control.errors) {
return [];
}
return Object.keys(this.control.errors)
.map(key =>
this.messages && key in this.messages && this.messages[key]
? this.messages[key]
: this.control.errors.customError
)
.filter(locString => !!locString);
}
}
|