this.moduleLoader.load(metadata.path).then((moduleFactory: NgModuleFactory<any>) => {
const moduleRef: NgModuleRef<any> = moduleFactory.create(this.injector);
const entryComponent = moduleRef["_providers"][0]._factories.entries().next().value[0];
const cmpFactory = moduleRef.componentFactoryResolver.resolveComponentFactory(entryComponent);
const cmpRef: ComponentRef<any> = this.vc.createComponent(cmpFactory, 0, this.injector);
cmpRef.instance.componentData = dc;
cmpRef.changeDetectorRef.detectChanges();
this.vc.insert(cmpRef.hostView);
resolve();
moduleRef["_providers"][0]._factories.entries().next().value[0];
import { ElementComponent } from './element.component';
"для создания компонентов на лету"
private loadComponent(metadata: ComponentMetadata, dc: Dynamic<any>): Promise<ComponentRef<any>> {
return new Promise(resolve => {
this.moduleLoader.load(metadata.path).then((moduleFactory: NgModuleFactory<any>) => {
this.compiler.compileModuleAndAllComponentsAsync(moduleFactory.moduleType)
.then((compiled: ModuleWithComponentFactories<any>) => {
const cmpFactory = compiled.componentFactories.find((component) => {
return component.componentType.name === metadata.code
});
const cmpRef: ComponentRef<any> = this.vc.createComponent(cmpFactory, 0, this.injector);
cmpRef.instance.componentData = dc;
cmpRef.changeDetectorRef.detectChanges();
this.vc.insert(cmpRef.hostView);
resolve();
});
});
});
}