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
Dharmeshwaran SPosted Jun 27, 2024, 2:00 PM
To resolve the error "Object is possibly NULL" in your code, you need to ensure that the values you are accessing are not null. TypeScript is strict about null checking, so you should include additional checks to handle these potential null values.