File

libs/playground-test-bbs/plugins/src/lib/escaped-max-length-validator/escaped-max-length-validator.module.ts

Index

Properties

Properties

customField (Optional)
Type TestInterface
escapedMaxLength
Type number
import { PLUGIN_VALIDATORS } from '@allianz/taly-core';
import { CommonModule } from '@angular/common';
import { Injector, ModuleWithProviders, NgModule, Signal, signal } from '@angular/core';
import { EscapedMaxLengthValidator } from './escaped-max-length-validator';
import { ESCAPED_MAX_LENGTH_PLUGIN_OPTIONS } from './tokens';

export const DEFAULT_OPTIONS: EscapedMaxLengthValidatorPluginOptions = {
  escapedMaxLength: 30
};

export interface EscapedMaxLengthValidatorPluginOptions {
  escapedMaxLength: number;
  customField?: TestInterface;
}

export interface TestInterface {
  bla: string;
  blu: Date;
}

@NgModule({
  providers: [
    {
      provide: PLUGIN_VALIDATORS,
      useClass: EscapedMaxLengthValidator,
      multi: true
    }
  ],
  imports: [CommonModule]
})
export class EscapedMaxLengthValidatorModule {
  static forRoot(
    optionsFactory?: (
      injector: Injector
    ) => Signal<EscapedMaxLengthValidatorPluginOptions | undefined>
  ): ModuleWithProviders<EscapedMaxLengthValidatorModule> {
    const defaultFactory = () => signal<EscapedMaxLengthValidatorPluginOptions>(DEFAULT_OPTIONS);
    return {
      ngModule: EscapedMaxLengthValidatorModule,
      providers: [
        {
          provide: ESCAPED_MAX_LENGTH_PLUGIN_OPTIONS,
          useFactory: optionsFactory || defaultFactory,
          deps: [Injector]
        }
      ]
    };
  }
}

results matching ""

    No results matching ""