I am writing an Angular 8 app and I am trying to lazy load some modules. However, when the page loads, I get this error:
Error: Component ProfileComponent is not part of any NgModule or the module has not been imported into your module.
Specifically, I wish to load a module when a route is hit and a component loads. The problem is that the component is part of the module.
Here is code for the sub module, where the component is defined:
@NgModule({
imports: [],
declarations: [
...
ProfileComponent
],
exports: [
...
ProfileComponent
]
})
export class ProfileModule { }
Here is the route definition in the parent module trying to dynamically load the sub-module:
const routes: Routes = [
{
path: 'projects/profile/:id', component: ProfileComponent,
loadChildren: () => {
return import('./profile/profile.module').then(m => m.ProfileModule);
},
children: [
{ path: 'list/:id', component: ListComponent, outlet: 'sidebar' },
{ path: 'risk/:id', component: RiskComponent, outlet: 'sidebar' },
...
]
}
Is there a way to load the Component and Module on navigate? I tried moving the offending ProfileComponent into the parent module, but it expects all of its sub components to exist when I navigate to the page (which is counter to the lazyloading). I can create a landing page that uses no sub components where I can click to redirect to my route that dynamically loads the sub module, but I would rather not add another layer of clicking to the app.