I'm currently working on implementing a custom validator for a form in Angular. I've encountered an issue where I am unable to access the controller's this
within the validator function.
This is the validator function that's causing trouble:
validateSuccessShortName(control: AbstractControl) {
// Unable to read this.randomProp, as this is undefined
if (control.value.length > this.randomProp.length) {
return {value: control.value};
}
return null;
}
For a demonstration of the problem, check out this STACKBLITZ.
Is there a mistake in my implementation or is it simply not achievable within the Angular framework?