### File

`src/lib/validators/is-equal-to.ts`

### Implements

`Validator`

### Metadata

Providers | `{ provide: NG_VALIDATORS, multi: true, useExisting: forwardRef(() => IsEqualToDirective), }`
Selector | `[rxapIsEqualTo]`
Standalone | `true`

### Index

###### Methods
Public registerOnValidatorChange Public validate
###### Inputs
rxapIsEqualTo
###### Accessors
equalTo

### Inputs

rxapIsEqualTo
Type : `any`
Required : true
Defined in src/lib/validators/is-equal-to.ts:31

### Methods

Public registerOnValidatorChange
`registerOnValidatorChange(fn: () => void)`
Defined in src/lib/validators/is-equal-to.ts:61
Registers a callback function to call when the validator inputs change. Parameters :
Name | Type | Optional | Description
fn | `function` | No | The callback function
Returns : `void`

Public validate
`validate(control: AbstractControl)`
Defined in src/lib/validators/is-equal-to.ts:43
Parameters :
Name | Type | Optional
control | `AbstractControl` | No
Returns : `ValidationErrors | null`

### Accessors

equalTo
set `equalTo(value: any)`
Defined in src/lib/validators/is-equal-to.ts:31
Parameters :
Name | Type | Optional
value | `any` | No
Returns : `void`

    import {
      Directive,
      forwardRef,
      Input,
    } from '@angular/core';
    import {
      AbstractControl,
      NG_VALIDATORS,
      ValidationErrors,
      Validator,
    } from '@angular/forms';
    import { Required } from '@rxap/utilities';

    @Directive({
      selector: '[rxapIsEqualTo]',
      providers: [
        {
          provide: NG_VALIDATORS,
          multi: true,
          useExisting: forwardRef(() => IsEqualToDirective),
        },
      ],
      standalone: true,
    })
    export class IsEqualToDirective implements Validator {

      @Input({
        required: true,
        alias: 'rxapIsEqualTo',
      })
      public set equalTo(value: any) {
        this._equalTo = value;
        if (this._onChange) {
          this._onChange();
        }
      }

      private _onChange!: () => void;

      private _equalTo!: any;

      public validate(control: AbstractControl): ValidationErrors | null {
        if (this._equalTo === null || this._equalTo === control.value) {
          return null;
        }
        return {
          isEqualTo: {
            value: this._equalTo,
            actualValue: control.value,
          },
        };
      }

      /**
       * @description
       * Registers a callback function to call when the validator inputs change.
       *
       * @param fn The callback function
       */
      public registerOnValidatorChange(fn: () => void): void {
        this._onChange = fn;
      }

    }

# results matching ""

# No results matching ""