Trying to achieve: Dynamic Forms as per user selected locale JSON using ngx-formly/material. How to map fields with my array of objects "this.fields2"?
In my component.ts I have:
model: any = {};
options: FormlyFormOptions = {};
fields: FormlyFeildCongif[];
Fetching the JSON of the selected Locale:
ngOnInit():void
{
this.langService.getSelectedLocaleData(this.cuurentLang).subscribe(
(res) =>
{
this.myDynamicForm = res.yBank.fields;
this.dynamicFormCreate(this.myDynamicForm);
});
}
public dynamicFormCreate(arr:any)
{
for(i=0; i< arrr.lenght; i++)
{
//here I am fetching data from json and creating an Object structure which is accepted by formly feilds
//the problem is how do I map this.fields2 array of objects with the formly feilds
this.fields2.push(
{
key: arr[i].type,
type: arr[i].type,
templateOptions:
{
label: arr[i].label,
placeHolder: arr[i].placeHolder,
description: arrp[i].description,
required: true
}
});
}
}
my component.html
<form [formGroup]="myForm">
<formly-form
[model]="model
[fields]="fields"
[options]="options"
[form]="myForm">
</formly-form>
</form>