We are currently using a method ViewContainerRef.createComponent()for dynamically creating components at runtime - this is a kind of plug-in system where the user can add plugins and display screens as he sees fit. The relevant code is here:
this.module = moduleFactory.ngModuleFactory.create(this.injector);
var factory = this.module.componentFactoryResolver.resolveComponentFactory(tab.type);
tab.component = this.container.createComponent(factory);
Where moduleFactoryis the factory for creating a dynamically loadable module. If I have a directive SomeDirectivethat I would like to apply to the created component, is this possible? The only current way I've seen is to create a template ( see here ), but it seems like a hack into the design, and I would really like to avoid this if possible.
Is anyone lucky with this? I see a parameter projectableNodes: any[][]in a call to createComponent, but I have no idea if this was relevant in this case. Thank!
source
share