I am deriving a custom validation method for validating ranges as shown below:
static ratingRange=(min:number,max:number) =>
{
return (control:AbstractControl):Promise<ValidationErrors|null>=>
{
return new Promise(resolve=>
{
if (control.value !== undefined && (isNaN(control.value)
|| control.value < min || control.value > max))
return resolve({InvalidRange:true});
else return resolve(null);
}
);
}
it is executing the validation as expected without any issue.
However for testing purpose i wanted to rewrite the validation method using ValidatorFn factory as shown below.(Intention was not to return a promise object)
static CustomRangeValidator (min:number,max:number): ValidatorFn
{
return (control:AbstractControl):{[key:string]:boolean}=>
{
if (control.value !== undefined && (isNaN(control.value)
|| control.value < min || control.value > max))
return {InvalidRange:true}
else return null;
}
}
But i am getting
'Expected validator to return Promise or Observable.'
Is there a way to refactor my function call without returning a Promise object?