In order to load dynamic componets i use materail tab as follows:
<md-tab-group [selectedIndex]="selectedTabIndex" *ngIf="tabs && tabs.length > 0">
<md-tab *ngFor="let tab of tabs">
<template md-tab-label>
{{tab.title}}
<span class="k-icon k-i-close mat-tab-close" (click)="close(tab)"></span>
</template>
<dcl-wrapper [type]="tab.component"></dcl-wrapper>
</md-tab>
</md-tab-group>
I want to load components into this tab from different modules. Loading process is done with dcl-wrapper as it is suggested in the following link:
https://stackoverflow.com/a/37154680/5285133
I give the seperate module component to the dcl-wrapper with webpack code splitting strategy.
require.ensure(["../../dmy/dmy.module"], (reqire : any) => {
let cmp = require("../../dmy/page/page2")["Page2"];
this.tabs.push({ title: "--", component: cmp });
this.selectedTabIndex = this.tabs.length - 1;
this._cdr.detectChanges();
}, "dmy");
But i get "No component factory found for Page2. Did you add it to @NgModule.entryComponents?" error.
I also tried to load seperate module components with SystemJsNgModuleLoader this way:
this._loader.load('../../dmy/dmy.module#DMYModule').then((factory: NgModuleFactory<any>) => {
console.log(factory);
});
It gives this error:
Error: Cannot find module '../../dmy/dmy.module'.? at webpackEmptyContext
Since i use tab component instead of routing, lazy load is not the solution that i want. So, i look for a way to get the instance of seperate module component.
Do you have any suggestion how i can load a seperate module and its components dynamically?