I'm trying to compare two input values in a custom validator. There should be an error if the minValue is greater than the maxValue.
FormGroup:
sumFormGroup = this.formBuilder.group({
from: ['', [Validators.min(0), sumValidator]],
to: ['', [Validators.min(0), sumValidator]]
});
custom validator:
function sumValidator (control: AbstractControl):{[key: string]: boolean} | null {
let minValue = control.get(this.sumFormGroup.get('from')).value;
let maxValue = control.get(this.sumFormGroup.get('to')).value;
if(minValue != maxValue){
return {'ageValidator': true}
}
return null;
};
Error in browser console:
ERROR TypeError: Cannot read property 'sumFormGroup' of undefined
at sumValidator in bla.ts
(...)
Can anyone help? Thank you