I came across this example in the official documentation at https://angular.io/guide/form-validation#custom-validators
return (control: AbstractControl): {[key: string]: any} => {
const forbidden = nameRe.test(control.value);
return forbidden ? {'forbiddenName': {value: control.value}} : null;
};
Can someone help me understand how to interpret this code snippet?
return (control: AbstractControl): {[key: string]: any} => {
return ...
}
It seems like it's returning a JavaScript object (control : object), but then why is there a lambda function?
The issue here is not what the function does, as that is explained in the documentation, but rather the syntax of the return statement.
Edit: I just learned that you can create a function like that, so now it makes sense to me.
Could someone please explain this to me? Thank you.