小编Lyc*_*zos的帖子

Angular 6/7 AOT:动态模板渲染-加载模块的JitCompiler

我在通过API响应“即时”构建模板时遇到了问题,但仅在AoT构建中存在问题。

我从后端收到了这样的回复:

<h1>Title...</h1> 
<some-component></some-componen> 
<p>other content</p>
Run Code Online (Sandbox Code Playgroud)

我想像常规的Angular模板一样解析它。

我组件的简化代码如下所示:


        import {
          Compiler,
          Component,
          ComponentFactory,
          ComponentRef,
          Injector,
          Input,
          NgModule,
          OnChanges,
          OnDestroy,
          OnInit,
          ViewContainerRef
        } from '@angular/core';
        import { CommonModule } from '@angular/common';
        import { RouterModule } from '@angular/router';

        export async function createComponentFactory(compiler: Compiler, metadata: Component): Promise> {
          const cmpClass = class DynamicComponent {
          };
          const decoratedCmp = Component(metadata)(cmpClass);

          // IMPORT ALL MODULES HERE!!!
          @NgModule({imports: [CommonModule, RouterModule], declarations: [decoratedCmp]})
          class DynamicHtmlModule {
          }

          const moduleWithComponentFactory = await compiler.compileModuleAndAllComponentsAsync(DynamicHtmlModule);
          return moduleWithComponentFactory.componentFactories.find(x => x.componentType === …
Run Code Online (Sandbox Code Playgroud)

jit dynamic aot angular

6
推荐指数
1
解决办法
1933
查看次数

标签 统计

angular ×1

aot ×1

dynamic ×1

jit ×1