I have developed an angular 5 application. I have divided my application into multiple modules like ReportModule, ProjectModule,etc. I am lazy loading these feature modules.
{ path: 'bulkrmchange', loadChildren: './modules/empwise/empwise.module#EmpwiseModule' }
My problem is when I am trying to load components in lazy loaded module as entry components, it is giving the following error.
Now I have researched a lot and found that we can use NgModuleFactoryLoader to resolve this issue. I have tried the below code.
ngAfterViewInit() {
const path = './modules/empwise/empwise.module#EmpwiseModule';
this.loader.load(path).then((moduleFactory: NgModuleFactory<any>) => {
const entryComponent = (<any>moduleFactory.moduleType).entry;
const moduleRef = moduleFactory.create(this.injector);
const compFactory = moduleRef.componentFactoryResolver.resolveComponentFactory(entryComponent);
this.cf.createComponent(compFactory);
});
}
But I am getting the following error.
Please help me in resolving this issue.
This is the code in the employee.component where I am trying to open the my modal component which is giving the error.This employee.component is loaded in my lazy module employee.module.ts and I am trying to open a modal component EmployeeWiseAllocationModalComponent inside this component.
openContinueModal(gridOptions: any) {
this.isBackDateAllocation = false;
// Remove ag-cell focus
$('.ag-cell-focus').removeClass('ag-cell-focus');
//Configuration settings for modal popup
const initialState = {
gridOptions: gridOptions,
components: this.components,
allocationGridData: this.allocationGridData,
refreshAllocations: this.ongettingEmplID.bind(this),
minStartDate: this.minStartDate,
minEndDate: this.minEndDate
};
this.bsModalRef = this.modalService.show(EmployeeWiseAllocationModalComponent, Object.assign({ initialState }, this.config, { class: 'gray pmodal' })); // Here I am using modal service top open modal popup
this.bsModalRef.content.closeBtnName = 'Close'; // Modal Title
}