我有很大的问题,因为我想检测动态生成表单的变化 . 当我创建表单并在其中创建具有输入元素的组件时 . NgForm无法检测到此输入,控件为空 . 有人知道这个问题的任何解决方案吗?
@Upadate
我想要检测每个下一个嵌套输入中的更改的示例代码
goo.gl/cYX2Q1
你没有提供任何代码,但我想你的问题 . 动态创建的组件会破坏数据绑定,这就是问题所在 . 您必须强制设置输入数据 .
看一下这个 . https://github.com/angular/angular/issues/6223
this.dcl.loadIntoLocation(ComponentToLoad, this.elementRef, 'host') .then((component) => { component.instance.inputValue = "whatever"; component.instance.outputValue.subscribe((value) => { // do smth }); });
我明白了,但我是最好的方式 . 在输入上我设置formGroup并通过方法 registerControl 添加每个输入 .
registerControl
https://plnkr.co/edit/OtCUhxT9B21jNBx2rGZ5
2 回答
你没有提供任何代码,但我想你的问题 . 动态创建的组件会破坏数据绑定,这就是问题所在 . 您必须强制设置输入数据 .
看一下这个 . https://github.com/angular/angular/issues/6223
我明白了,但我是最好的方式 . 在输入上我设置formGroup并通过方法
registerControl
添加每个输入 .https://plnkr.co/edit/OtCUhxT9B21jNBx2rGZ5