尝试实现:根据用户使用 ngx-formly/material 选择区域设置 JSON 的动态表单。如何用我的对象数组“this.fields2”映射字段?
在我的 component.ts 中,我有:
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
}
});
}
}
我的 component.html
<form [formGroup]="myForm">
<formly-form
[model]="model
[fields]="fields"
[options]="options"
[form]="myForm">
</formly-form>
</form>