I have a large application, that I have decided to split into multiple lazy loaded modules. While this worked for 'smaller' modules, for the bigger ones, I discovered that sometimes/most of the time, the views related to these modules, are not run with angulars change detection, like nothing had changed.
The application itself its quite large, so to sum it up, gonna post a 'snippet bellow'. The changes that come from the logic layer, like waiting for services to finish, and showing the results in the template, its not updating.
The weird part is that once I hit a key on the keyboard, it resumes, or either calling manual detection with ChangeDetectorRef
markForCheck
. This behavior happens randomly, and mostly for the bigger lazy loaded modules.
Has anyone had any issues before with lazy loaded modules, its the first time Im using this approach and maybe Im missing something, any help is very much appreciated. The template used its a regular one, having subscriptions on the ngOnInit
level, nothing really fancy about it. The services are called, I've checked it multiple times, but the issue is that the data rendered in the view does not update. This exact component worked perfect, until the change into a lazy loaded module.
Lazy loaded module:
@NgModule({
imports: [
...multiple modules
RouterModule.forChild(homeRoutes),
],
providers: [...multiple services],
declarations: [HomeComponent]
})
export class HomeModule {
}
Parent where this module is called(which is called in the appModule)
@NgModule({
imports: [
CommonModule,
FormsModule,
HttpClientModule,
MatTooltipModule,
AppRoutingModule,
BrowserAnimationsModule,
RouterModule.forChild(mainRoutes),
ToolsModule,
BMWTranslateModule,
ModalModule,
],
providers: [HttpClient, MainServiceState, AppState, RouterService, ...etc],
declarations: [MainComponent, NavbarComponent],
exports: [MainComponent]
})
export class MainModule {
}
and the router associated with it:
export const mainRoutes: Routes = [
{
path: 'home',
loadChildren: './../home/#HomeModule'
},
{...other lazy loaded modules}]