|
appearance
|
Type : ErrorStyleType
|
Default value : inject(ERROR_DEFAULT_OPTIONS, { optional: true })?.appearance ?? (inject<CHANNEL>(CHANNEL_TOKEN) === CHANNEL.EXPERT ? 'text' : 'message')
|
|
|
nx-error appearance. Only use this to override default behavior: text for Expert and
message for Retail.
|
|
isInputDateYear
|
Type : boolean
|
Default value : false
|
|
|
Methods
|
getErrorMessageStreams
|
getErrorMessageStreams()
|
|
|
|
Returns : Observable[]
|
|
Readonly
errorMessages$
|
Type : unknown
|
Default value : computed(() => this.getErrorMessageStreams())
|
|
|
import { ERROR_DEFAULT_OPTIONS, ErrorStyleType } from '@allianz/ng-aquila/base';
import { CHANNEL, CHANNEL_TOKEN, ValidationConfig } from '@allianz/taly-core';
import { ChangeDetectionStrategy, Component, computed, inject, input } from '@angular/core';
import { ValidationErrors } from '@angular/forms';
import { Observable } from 'rxjs';
import { ValidationErrorsService } from './validation-errors.service';
@Component({
selector: 'taly-validation-errors',
templateUrl: 'validation-errors.component.html',
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ValidationErrorsComponent {
readonly isInputDateYear = input(false);
readonly controlErrors = input<ValidationErrors | null | undefined>();
readonly errorMessages = input<ValidationConfig[], ValidationConfig[] | undefined>([], {
transform: (value) => value?.filter((config) => config.validatorName) ?? []
});
/** `nx-error` appearance. Only use this to override default behavior: `text` for Expert and
* `message` for Retail. */
readonly appearance = input<ErrorStyleType>(
inject(ERROR_DEFAULT_OPTIONS, { optional: true })?.appearance ??
(inject<CHANNEL>(CHANNEL_TOKEN) === CHANNEL.EXPERT ? 'text' : 'message')
);
private validationErrorsService = inject(ValidationErrorsService);
readonly errorMessages$ = computed(() => this.getErrorMessageStreams());
getErrorMessageStreams(): Observable<string>[] {
return this.validationErrorsService.resolveErrorMessages({
controlErrors: this.controlErrors() ?? {},
validationConfigs: this.errorMessages(),
isInputDateYear: this.isInputDateYear()
});
}
}
@for (message$ of errorMessages$(); track $index) {
<nx-error [appearance]="appearance()">
{{ message$ | async }}
</nx-error>
}
Legend
Html element with directive