1 import {Directive, Input} from '@angular/core';
2 import {NG_VALIDATORS, AbstractControl, FormControl, ValidationErrors, ValidatorFn} from '@angular/forms';
3 import {Injectable} from '@angular/core';
5 import * as Moment from 'moment-timezone';
7 export function notBeforeMomentValidator(notBeforeMe: Moment): ValidatorFn {
8 return (control: AbstractControl): {[key: string]: any} | null => {
9 return (control.value && control.value.isBefore(notBeforeMe)) ?
10 {tooEarly: 'This cannot be before ' + notBeforeMe.format('LLL')} : null;
15 selector: '[egNotBeforeMoment]',
17 provide: NG_VALIDATORS,
18 useExisting: NotBeforeMomentValidatorDirective,
22 export class NotBeforeMomentValidatorDirective {
23 @Input('egNotBeforeMoment') notBeforeMoment: Moment;
25 validate(control: AbstractControl): {[key: string]: any} | null {
26 return this.notBeforeMoment ?
27 notBeforeMomentValidator(this.notBeforeMoment)(control)