Ramco Ramco

Ramco Ramco

  • 443
  • 3.4k
  • 526.4k

Object is possibly NULL

Jun 27 2024 9:51 AM

Hi

  I am getting getting error on these 2 fields startAT,EndAt. Using Angular 17.

export class DateRangeValidatorDirective implements Validator {
  validate(control: AbstractControl): ValidationErrors | null {
    const start: Date = control.get('startAt').value;
    const end: Date = control.get('endAt').value;

    if (start && end) {
      const isRangeValid = end.getTime() - start.getTime() > 0;
      return isRangeValid ? null : { dateRange: true };
    }

    return null;
  }
}

Thanks


Answers (1)