I'm trying to use custom validator to compare if the end time is greater than the start time.
code:
function timeValidator(): ValidatorFn {
return (control: AbstractControl): { [key: string]: boolean } | null => {
if (control.value !== undefined && (isNaN(control.value) || control.get('fromTime').value > control.get('toTime').value)) {
return { 'ageRange': true };
}
return null;
};
}
From formgroup
toTime: new FormControl(null, [Validators.required, timeValidator(this.fromTime,this.toTime)]),
I'm getting a error once I run this like: Cannot read property 'value' of null on the line if (control.value !== undefined && (isNaN(control.value) || control.get('fromTime').value > control.get('toTime').value))
I need some help in fixing this. Thank you