我正在尝试创建动态表单&到目前为止一切正常,我得到的问题是ngModel,目前我有这样的json:
function(fn : BeforeHookCallbackMode | BeforeHookRegularMode | BeforeHookObservableMode | BeforeHookEEMode) {
}
我的表单结构存储在this.value= {
phone: [
{
type: mobile,
number: '123'
},
{
type: landline,
number: '321'
}
],
email: [
{
type: work,
number: 'xyz'
},
{
type: personal,
number: 'zyx'
}
]
}
中,因此存储了手机和结构的结构。电子邮件如:
this.fieldPermission.fieldFormStructure
这是我的组件有形式元素&负责编辑/增加电话/电子邮件的价值:
this.fieldPermission.fieldFormStructure = {
'phone': {
'type': 'text',
'label': 'Phone number',
'key': 'phone',
'binding_key': 'number',
'value': ''
},
'email': {
'type': 'email',
'label': 'Email',
'key': 'email',
'binding_key': 'address',
'value': '',
'validation': {
'pattern': ''
}
}
}
父组件正在迭代上面的模板,如:
<input class="form-control"
*ngIf="['text', 'email'].indexOf(fieldPermission.fieldFormStructure[field].type) != -1"
[formControlName]="fieldPermission.fieldFormStructure[field].key"
[id]="fieldPermission.fieldFormStructure[field].key"
[type]="fieldPermission.fieldFormStructure[field].type"
[placeholder]="fieldPermission.fieldFormStructure[field].label"
[(ngModel)]="valueModel"
[ngModelOptions]="{ standalone : true }">
因此,当<div
*ngFor="let field of fieldPermission.structureList">
<div class="form-field-block"
*ngFor="let value of data[field]; let i = index; ">
<form-base
[valueModel]="value[fieldPermission.fieldFormStructure[field].binding_key]"
[field]="field"
[form]="form"
[index]="i"></form-base>
</div>
</div>
只有一个值时,这种方式可以正常工作,但如果现在有多个类似的话会中断,则会出现此错误:this.value.phone
。所以我认为我可以通过添加Expression has changed after it was checked. Previous value: '123'. Current value: '321'
来解决此问题,但这会产生另一个错误:[ngModelOptions]="{ standalone : true }"
很抱歉,很难在plunker中显示正在运行的代码