File

src/lib/validation-error.directive.ts

Description

The context of the ValidationErrorDirective

Index

Properties

Properties

$implicit
$implicit: string | null
Type : string | null

The label

error
error: any
Type : any

The error

import { Directive, input, TemplateRef, inject } from '@angular/core';

/**
 * The context of the ValidationErrorDirective
 */
interface ValidationErrorContext {
  /**
   * The label
   */
  $implicit: string | null;

  /**
   * The error
   */
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  error: any;
}

/**
 * Directive allowing to define the template for an error of a given type (using the `valError` input), using an ng-template.
 * It's used inside the body of the validation errors component, or inside the body of the default validation errors directive.
 * See the documentation of these two for example usages.
 */
@Directive({
  selector: 'ng-template[valError]'
})
export class ValidationErrorDirective {
  templateRef = inject<TemplateRef<ValidationErrorContext>>(TemplateRef);

  /**
   * The type of the error that the content of the template must display.
   */
  type = input.required<string>({ alias: 'valError' });

  static ngTemplateContextGuard(directive: ValidationErrorDirective, context: unknown): context is ValidationErrorContext {
    return true;
  }
}

results matching ""

    No results matching ""