【问题标题】:Angular 2 dynamic form binding won't workAngular 2 动态表单绑定不起作用
【发布时间】:2017-07-20 20:58:01
【问题描述】:

我正在使用 Angular 2(或 4)创建一个动态表单,其中一个表单数组(房间)嵌套了一个表单数组(子)。

children 数组不会绑定.value 表单属性中的控件和值,即使它们被添加到其中。

这里是 plunkr:https://embed.plnkr.co/DjtLLt0vS0qmmvgqKhN8/

我想念什么?

【问题讨论】:

    标签: angular


    【解决方案1】:

    您有一个简单的错误,请从您的 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

    【讨论】:

      猜你喜欢
      • 2017-06-16
      • 2014-06-24
      • 1970-01-01
      • 2017-02-17
      • 1970-01-01
      • 2016-07-19
      • 1970-01-01
      • 1970-01-01
      • 2021-01-21
      相关资源
      最近更新 更多