I have a lazy loaded module, and I have a route like this inside the lazy loaded module:
{
path: 'window',
component: CustomerFormComponent,
canActivate: [FormGuard],
}
I use the FormGuard to stop the navigation and open a dialog. I instantiate the component CustomerFormComponent dynamically, which is rendered in a window. Everything was working fine until I moved these routes into a new module (using loadChildren in the route) in order to lazy load the module. I am having this error because it cannot resolve the component when calling this.componentFactoryResolver.resolveComponentFactory(componentType)
.
ERROR Error: No component factory found for CustomerFormComponent. Did you add it to @NgModule.entryComponents?
at noComponentFactoryError (core.js:18113)
Obviously, if I add the component in entryComponents
in app.module.ts it works, but if I'm not wrong this defeats the purpose of lazy loading, doesn't it?.
What would be the correct approach?