ValidatorOptional

match

Check that a control equals a sibling, such as a password confirmation.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrInput } from 'ngwr/input';
import { WrValidators } from 'ngwr/validators';

@Component({ imports: [WrInput] })
export class MyComponent {}

Live demo

confirm.errors: null

Usage

import { FormControl, FormGroup } from '@angular/forms';
import { WrValidators } from 'ngwr/validators';

const form = new FormGroup({
  password: new FormControl(''),
  confirm:  new FormControl('', [WrValidators.match('password')]),
});

Initial mismatch

Code that reads form.valid before the template binds misses it; add matchFields to the group.

API

NameDescriptionTypeDefault
signatureCall it with the sibling control name.(name: string) => ValidatorFn—
lookupReads control.parent.get(name). Passes when the parent or the sibling is missing.——
error keyOn mismatch: { match: { target: 'password' } }. A filled value against an empty one fails.{ match: { target } }—
initial valuesNot reported until the control revalidates. Add matchFields to the group.——

See also