Angular:在根模块中加载JIT编译的Dynamic模块

时间:2018-05-23 13:28:23

标签: angular routing

我已经生成了一个JIT编译模块,但无法在根模块中加载它。任何帮助将不胜感激..这是我现在的第三天这个问题

JIT编译模块 - dynaModule

let dynaModule = NgModule({
        declarations: dyna_comps,
        exports: dyna_comps,
        imports: [CommonModule, RouterModule.forChild([
            {
                path: 'cc1',
                component: dyna_comps[0]
            },
            {
                path: 'cc2',
                component: dyna_comps[1]
            }
        ]),
        ],
        providers: [GlobalService], //- e.g.if your dynamic component needs any service, provide it here.

    })(class { });

this.compiler.compileModuleAndAllComponentsAsync(dynaModule)
        .then((factories) => {
            for (let i = 0; i < factories.componentFactories.length; i++)
            {
                const f = factories.componentFactories[i];
                this.cmpRef = f.create(this.injector, [], null, this.moduleRef);
                this.cmpRef.instance.name = 'DCOMP' + i;                  
            }    
     });

对于静态模块,我可以使用router.resetConfig方法延迟加载它

this.router.resetConfig([
        ...this.router.config,
        {
            path: 'c',
            loadChildren: '../static/static.module#StaticModule'               

        }
    ]);

如何在根模块中加载此JIT编译dynaModule,以便我可以完成路由?

0 个答案:

没有答案