.forChild() usage with lazy loading routes
See original GitHub issueI’m submitting a … (check one with “x”)
[ ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[x] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request
Current behavior
AppModule
export function createTranslateLoader(http: Http) {
return new TranslateHttpLoader(http, "/i18n/", "/index.json");
}
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: createTranslateLoader,
deps: [Http]
}
}),
]
SharedModule
imports: [
//TranslateModule
],
exports: [
//TranslateModule,
]
AdminModule
export function createTranslateLoader(http: Http) {
return new TranslateHttpLoader(http, "/i18n/", "/admin.json");
}
imports: [
TranslateModule.forChild({
loader: {
provide: TranslateLoader,
useFactory: createTranslateLoader,
deps: [Http]
}
}),
]
Expected/desired behavior
I would like to load additional JSON files per component / module, i.e. an admin.json for the administration panel of our app.
I would like to import one TranslateModule inside of SharedModule
and configure it allow all modules that don’t explicite call .forChild().
Both doesn’t work, it simply doesn’t load the admin.json and hence doesn’t translate strings defined in that file.
Please tell us about your environment:
-
ngx-translate version: 6.0.0-beta.1
-
Angular version: 2.4.7
-
Browser: [Firefox 51.0.1]
-
Language: [TypeScript 2.0]
Issue Analytics
- State:
- Created 7 years ago
- Reactions:47
- Comments:53 (5 by maintainers)
Top Results From Across the Web
Lazy-loading feature modules - Angular
To lazy load Angular modules, use loadChildren (instead of component ) in your AppRoutingModule routes configuration as follows. AppRoutingModule (excerpt)
Read more >How To Use Lazy Loading Routes in Angular | DigitalOcean
To lazy load Angular modules, use loadChildren (instead of component ) in your AppRoutingModule routes configuration as follows. content_copy ...
Read more >How to Nest Lazy-Loaded Modules - DEV Community
This route is now lazy-loaded. Note that in this module we use the forChild() method instead of forRoot(). You must do this for...
Read more >Routing and Lazy Loading with Angular's Standalone ...
It allows to get hold of all the providers defined in existing NgModules and hence is the key for using them with Standalone...
Read more >How to Nest Lazy-Loaded Modules - Medium
A not-nested, lazy-loaded module. This route is now lazy-loaded. Note that in this module we use the forChild() method instead of forRoot().
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
appModule.ts
Create one shared module translateSharedModule.ts
appComponent.ts import {TranslateService} from ‘@ngx-translate/core’; constructor(public translate: TranslateService) { translate.setDefaultLang(‘en’);
}
homeModule.ts //or any other submodules import { TranslateSharedLazyModule } from ‘…/…/Common/translateSharedLazyModule’; imports : [
TranslateSharedLazyModule ], …
Since I didn’t found any plunker working with ngx-translate librairy and I also had some difficulties to manage to make it work with LoadChildren, I’ve setup a way that work pretty well for me:
I’ve created two SharedModules, (one for lazyLoading and one for the other part of my application)
SharedLazyModule for lazy loading content:
SahredModule for App
See Plunker: https://plnkr.co/LVmIuI1Xw9vFn0IuC2jW