【发布时间】:2017-07-20 20:58:01
【问题描述】:
我正在使用 Angular 2(或 4)创建一个动态表单,其中一个表单数组(房间)嵌套了一个表单数组(子)。
children 数组不会绑定.value 表单属性中的控件和值,即使它们被添加到其中。
这里是 plunkr:https://embed.plnkr.co/DjtLLt0vS0qmmvgqKhN8/
我想念什么?
【问题讨论】:
标签: angular
我正在使用 Angular 2(或 4)创建一个动态表单,其中一个表单数组(房间)嵌套了一个表单数组(子)。
children 数组不会绑定.value 表单属性中的控件和值,即使它们被添加到其中。
这里是 plunkr:https://embed.plnkr.co/DjtLLt0vS0qmmvgqKhN8/
我想念什么?
【问题讨论】:
标签: angular
您有一个简单的错误,请从您的 addChild() 中删除最后一个 controls:
addChild(i: number) {
const control =
//remove the last 'controls'
this.searchform.controls.rooms).controls[i]).controls["children"].controls;
control.push(this.initAge());
}
而是:
addChild(i: number) {
const control =
this.searchform.controls.rooms).controls[i]).controls["children"];
control.push(this.initAge());
}
这是你的分叉 plunker:https://plnkr.co/edit/SmnjBroGHufori1PWNSR?p=preview
【讨论】: