libs/core/ui/src/validation-errors/validation-errors.component.ts

Metadata

Relationships

Depends on

No results matching.

Index

Properties
Methods
Inputs

Inputs

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.

controlErrors
Type : ValidationErrors | null | undefined
errorMessages
Type : ValidationConfig[]
Default value : []
isInputDateYear
Type : boolean
Default value : false

Methods

getErrorMessageStreams
getErrorMessageStreams()
Returns : Observable[]

Properties

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
Component
Html element with directive

results matching ""

    No results matching ""