In Angular4, you can lazy load your module using the loadChildren
attribute in your routing config with pathToMyModule#MyModule
. I was wondering if there was any attribute I could specify to always load my module (so basically disabling the lazy loading).
Asked
Active
Viewed 4,670 times
5

Nicholas K
- 15,148
- 7
- 31
- 57

Scipion
- 11,449
- 19
- 74
- 139
-
read this article [Avoiding common confusions with modules in Angular](https://blog.angularindepth.com/avoiding-common-confusions-with-modules-in-angular-ada070e6891f) – Max Koretskyi Oct 15 '17 at 05:49
1 Answers
4
import all the modules in the module that you bootstrap when you start the application. In general it is called AppModule
. It is the default way though. Then don't use loadChrildren
. The modules should import each other hierarchically, then all modules will be imported eagerly.
@NgModule({
imports: [
AppRoutingModule,
LoginModule,
//here you should import all other modules, or other the modules should import each other hierarchically
],
declarations: [
AppComponent
],
bootstrap: [AppComponent]
})
export class AppModule {
}
@NgModule({
imports: [
RouterModule.forRoot([
{path: '', component: SomeComponent}
],
exports: [
RouterModule
]
})
export class AppRoutingModule {
}
@NgModule({
imports: [
LoginRoutingModule
]
})
export class LoginModule {
}
@NgModule({
imports: [
RouterModule.forChild([
{
path: 'login',
children: [
{path: '', pathMatch: 'full', redirectTo: 'somepath'},
{path: 'somepath', component: SomeOtherComponent},
]
}
])
],
exports: [
RouterModule
]
})
export class LoginRoutingModule {
}

omeralper
- 9,804
- 2
- 19
- 27