How can I transform this string array into an array of validator functions?
let valStrings: string[] = ["Validators.required", "Validators.maxLength(10)"];
Convert it to:
let validators: ValidatorFn[] = [ Validators.required, Validators.maxLength(10) ];
I am working on centralizing validation rules for our web application to ensure consistency between server and client validation. These strings are retrieved from a HttpClient
call with a JSON response.
The array of validators will be used in a FormControl
to enable reactive form validation in Angular.
Should I consider using eval()
in this scenario?
Thanks -Adam