I have a service called routing.service which subscribes to routing event and when a parameter changes, it updates Translate service. As following in constructor:
this.router.events.subscribe(val => {
if (val instanceof ActivationEnd ) {
let myVal = val.snapshot.params.lang;
this.currentLang = myVal;
this.translate.use(myVal);
this.translate.setDefaultLang(config.defaultLang);
}
});
I have a shared module that is imported into the app module. In shared component everything works fine:
<div [innerHTML]="'HOME.TITLE' | translate"></div>
But in my lazy loaded modules not working. Even I can't access to this.currentLang that is inside subscribe. Any idea?
Update: Here is more detail about my code:
app.module:
imports:[
CommonModule,
BrowserModule,
FormsModule,
NgtUniversalModule,
TransferHttpCacheModule,
HttpClientModule,
AppRoutingModule,
SharedModule
],
shared.module:
imports: [
CommonModule,
RouterModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateUniversalLoader,
}
})
],
exports: [
HeaderComponent,
TranslateModule
]
lazy-loaded.module:
imports: [
CommonModule,
FormsModule,
CustomersRoutingModule,
SharedModule,
],
My app.component:
<!-- This is component of my shared.module and translation works fine here, but not in lazy loaded modules -->
<saz-header></saz-header>
<router-outlet></router-outlet>
move your routing.service possibly into your AppModulemove your routing.service possibly into your AppModule, I assumed your routing.service isn't a provider in your AppModule. Would you kindly share your AppModule, SharedModule and lazy loaded module files so we can see how everything is imported/etc?Updatepart. Thanks.