How do you use @Input with components created with a ComponentFactoryResolver?
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);
The Günter Zöchbauer's answer is correct. But if you, like I was, have troubles with rendering @Input
data in the component template, you should try this:
- Run your component creating code in
ngAfterViewInit
. - Add
componentRef.instance.ngOnInit()
as a last line. - Inside
ngOnInit
of your dynamically created component rundetectChanges
method of theChangeDetectorRef
.