Angular 4 ngComponentOutlet 和延迟加载模块

Angular 4 ngComponentOutlet and lazy loading modules

我目前开始掌握 angular 4 的窍门,特别是动态组件部分。

我成功地复制了 ngComponentOutlet 方法, plunkr here

现在我想做的是延迟加载一个包含动态组件的模块。我看到 on Github 应该已经实现了此功能,但我在 angular 4 方面经验不足,无法自己解释源更改,而且我在任何地方都找不到这种方法的示例。

此外,我想在不依赖 a4 路由器和 webpack(如果重要的话)的情况下实现这种延迟加载。

有人愿意帮忙吗?

TIA

可以使用编译器的方法compileModuleAndAllComponentsAsync。沿着这些线的东西:

ngAfterViewInit() {
  System.import('app/t.module').then((module) => {
      _compiler.compileModuleAndAllComponentsAsync(module.TModule)
        .then((compiled) => {
          const m = compiled.ngModuleFactory.create(this._injector);
          const factory = compiled.componentFactories[0];
          const cmp = factory.create(this._injector, [], null, m);
        })
    })
}

有关详细信息,请阅读 Here is what you need to know about dynamic components in Angular