用于动态的 Angular2 AOT HTML

Angular2 AOT for dynamic HTML

我在 Angular2 应用程序中使用 Angular2-Component-Outlet 动态 HTML 并且它有效。但是现在当我尝试创建 AOT 时,我仍然需要为 Angular2-Component-Outlet 加载 RuntimeCompiler。

有什么办法也可以 AOT 编译动态 HTML 并使用延迟加载加载模块。

旧的 Plunker 展示了 Angular2-Component-Outlet 用于放置动态内容的用法。这类似于 AngularJS ng-include 指令。

首先,angular2-component-outlet 已停产,取而代之的是 ng-dynamic

无论哪种方式,两种解决方案都需要 RuntimeCompiler 的依赖性。如果您考虑一下,这是有道理的。它是一个动态组件,基于我猜测的用户输入。或者至少是提前编译器事先不知道的输入。

为了能够在运行时编译此输入,您需要 RuntimeCompiler。我看不出有什么办法。

加法

来自 ng-dynamic 自述文件:

dynamicComponent Constraints

dynamicComponent needs RuntimeCompiler. You can use AoT compilation, but you cannot eliminate the dependency on @angular/compiler.

我可以通过采用 Angular2 文档中设计的 Dynamic Form 方法来完成整个项目的 AOT。