I'm using angular 8 and I wrote a dynamic form. I want to write a validator mapper form to validate my form controles but it doesn't work correctly.
ts
for (const prop of this.formConfig) {
this.form.addControl(
prop.id, new FormControl(
prop.value,
this.mapValidator(prop.validationvalidations)
)
)
}
mapValidator(validators) {
if (validators) {
validators.forEach(validator=>{
if (validator.type=='required') {
return [Validators.required];
}})
} else {
return [];
}
}
config
"formConfig": [
{
"name": "firstName",
"label": "name ",
"value" : "",
"id" : "1"
"type": "text",
"validations": [
{
"type": "required"
}
]
}