How do you use @Input with components created with a ComponentFactoryResolver?

后端 未结 1 1594
慢半拍i
慢半拍i 2020-12-13 03:14

Is there a method that can be used to define an @Input property on an Angular 2 component that\'s created dynamically?

I\'m using the ComponentFactoryResolver to cre

相关标签:
1条回答
  • 2020-12-13 04:02

    No, Angular2 bindings only work with components and directives statically added to the template of a component.

    For all other situations use shared services like explained in https://angular.io/guide/component-interaction#parent-and-children-communicate-via-a-service

    You can also use

    let componentRef = entryPoint.createComponent(componentFactory);
    componentRef.instance.someProp = 'someValue';
    componentRef.instance.someObservableOrEventEmitter.subscribe(data => this.prop = data);
    
    0 讨论(0)
提交回复
热议问题