I am making dynamic forms in Angular 6 . For that i am sending JSON from backend . PFB the json
[
{
"controlType": "input",
"label": "Test1",
"key": "some1",
"value": "This input is pre-populated",
"syncValidators": "Validators.required"
}
]
I am making the forms in Typescript as follows. PFB the code
this.dataList = JSON.parse(event.body); //Contains the JSON sent from backend
const formContent: any = {};
this.dataList.forEach(data => {
formContent[data.key] = new FormControl(data.value ,data.syncValidators));
});
this.exampleForm = new FormGroup(formContent);
I am getting the problem in => data.syncValidators , as it is treated as a string . But it needs to be Validators.required .
How can i make the conversion so that 'data.syncValidators' will be taken as a method not as a string ?