import { Directive , Input } from '@angular/core' ; import { AbstractControl , NG_VALIDATORS , Validator , ValidatorFn } from '@angular/forms' ; export function confirmValidator ( value ) { return ( control ) : { [ key ] : any ; } | null => { const isEqual = value === control . value ; return ! isEqual ? { confirm : { value : value , actual : control . value } } : null ; } ; } @ Directive ( { selector : '[confirm]' , providers : [ { provide : NG_VALIDATORS , useExisting : ThyConfirmValidatorDirective , multi : true } ] } ) export class ThyConfirmValidatorDirective implements Validator { @ Input ( ) confirm : string ; validate ( control ) { return confirmValidator ( this . confirm ) ( control ) ; } }