我有一个来自后端的随机标记,应该在运行时使用JiT进行编译。此标记中使用的每个组件都已使用AoT预编译(添加到entryComponents块),因此在运行时具有组件工厂。当JiT编译提供标记时,它会忽略现有的组件工厂并重新编译每个内部组件 有没有办法向JiT compilator提供组件的AoT预编译工厂,只用动态模板编译一个动态组件?
应该编译的标记看起来像这样
<exercise1 smth="smth">
<exercise1-answer>smth</exercise1-answer>
</exercise1>
<some-wrapper-cmp>
<exercise2 smth="smth">
<exercise2-answer>smth</exercise2-answer>
</exercise2>
</some-wrapper-cmp>
具有任意嵌套(常规标记可包含1500-2000个DOM节点)
P.S。我用这种方式用AoT获得JiT https://github.com/angular/angular/issues/15510#issuecomment-294301758,然后只用
const component = Component({ template })(class {});
const module = NgModule({ imports, declarations: [ component ], schemas })(class {});
this.compiler.compileModuleAndAllComponentsAsync(module)
.then(factories => factories.componentFactories.filter(factory => factory.componentType === component)[0])
.then(componentFactory => {
this.componentRef = this.viewContainerRef.createComponent(
componentFactory,
null,
this.viewContainerRef.injector
);
this.compilationEnd.emit();
});`enter code here`