I am using Angular 5.2.10 and trying to make application to lazy loading.so creating new module for AuditorloginComponent
and i have removed my AuditorloginComponent
from app.module.ts
auditorlogin.module.ts
@NgModule({
imports: [
CommonModule,
AuditorloginRoutingModule,FormsModule
],
declarations: [AuditorloginComponent]
})
export class AuditorloginModule { }
auditorlogin-routing.module.ts
const routes: Routes = [
{
path: '',
component: AuditorloginComponent
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class AuditorloginRoutingModule { }
app.routing.ts
I have added loadChildren
{
path: 'auditorlogin',
loadChildren: 'app/auditor/auditorlogin/auditorlogin-routing.module#AuditorloginRoutingModule',
pathMatch: 'full'
},
But i am getting
core.js:1449 ERROR Error: Uncaught (in promise): Error: Component AuditorloginComponent is not part of any NgModule or the module has not been imported into your module.
Error: Component AuditorloginComponent is not part of any NgModule or the module has not been imported into your module
Kindly tell to me where is my mistake?
Lazy loading is the process of loading components, modules, or other assets of a website as they're required. Since Angular creates a SPA (Single Page Application), all of its components are loaded at once. This means that a lot of unnecessary libraries or modules might be loaded as well.
Lazy loading is a technique in Angular that allows you to load JavaScript components asynchronously when a specific route is activated. It improves the speed of the application load time by splitting the application into several bundles. When the user navigates through the app, the bundles are loaded as required.
If you want to check how lazy loading works and how lazy loading routing flow, then Augury is the best tool we have. Click on ctrl+F12 to enable the debugger and click on the Augury tab. Click on the router tree. Here, it will show the route flow of our modules.
To lazy load Angular modules, use loadChildren (instead of component ) in your AppRoutingModule routes configuration as follows. content_copy const routes: Routes = [ { path: 'items', loadChildren: () => import('./items/items. module'). then(m => m.
you don't have your component in AuditorloginRoutingModule
declarations:[...]
Your problem is in AuditorloginRoutingModule
. you must be added AuditorloginComponent
in declration like this
const routes: Routes = [
{
path: '',
component: AuditorloginComponent
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
declarations: [
// components that are used will be added here.
AuditorloginComponent]
})
export class AuditorloginRoutingModule { }
You are only lazy loading the routing module, while you should load the AuditorloginModule
which then uses the AuditorloginRoutingModule
for routing and not the other way round.
{
path: 'auditorlogin',
loadChildren: 'app/auditor/auditorlogin/auditorlogin.module#AuditorloginModule',
pathMatch: 'full'
},
Change AuditorloginModule to
@NgModule({
imports: [
CommonModule,
AuditorloginRoutingModule,FormsModule
],
declarations: [AuditorloginComponent],
export: [AuditorloginComponent]
})
export class AuditorloginModule { }
And then declare AuditorloginComponent to any module which you want to use it in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With