1

请帮助我了解如何进行从父级到动态创建的组件的双向数据绑定。

这是父组件部分:

ngOnInit() {
  let factory: ComponentFactory<any> = 
    this._componentFactoryResolver.resolveComponentFactory(this.ComponentType); 
  this._Component = this._viewContainer.createComponent(factory);
  this._Component.instance.Value = this.Value;
  this._Component.changeDetectorRef.detectChanges(); // What does it do? :(
}

动态创建的组件:

@Input() Value: any; // But I think @Input decorator is useless here?

父母或孩子的任何价值变化都不会相互影响。对我来说,我没有看到任何进行数据绑定的代码行,这并不奇怪。

请帮助我或给我一个正确的挖掘方法。

谢谢你。

4

0 回答 0