如何将多个angular2子应用程序动态集成到一个父角度应用程序中

时间:2016-09-28 12:34:38

标签: angular angular2-routing angular2-template

我正在研究一个用例,我需要在主要的父应用程序中放置多个ng2应用程序。我可以使用systemjs bundle配置和' loadChildren'来管理路由。 angular2 Routes中的属性,但子应用程序可以有单独的路径和单独的systemjs配置。怎么做到这一点?

1 个答案:

答案 0 :(得分:0)

您可以延迟加载多个@NgModules,其中每个模块都是一个单独的应用程序。

compRef: ComponentRef<any>; 
constructor(private moduleLoader: SystemJsNgModuleLoader) { }

this.moduleLoader.load(`/path/to/my/app`)
  .then((moduleFactory: NgModuleFactory<any>) => {
    const vcRef = this.vcRef;
    const ngModuleRef = moduleFactory.create(vcRef.parentInjector);
    const comp = ngModuleRef.injector.get(LazyLoadConfig).component;
    const compFactory = ngModuleRef.componentFactoryResolver.resolveComponentFactory(comp);
    this.compRef = vcRef.createComponent(compFactory, 0, ngModuleRef.injector);
  });

查看this plunker的工作示例。

相关问题