[Question] How do you export TranslateStaticLoader from a SharedModule
See original GitHub issueSo we have a pretty big project (Ionic 2) with lots of smaller ngModules.
We were hoping that you could export a preconfigured TranslateModule like so:
export function createTranslateLoader(http: Http) {
return new TranslateStaticLoader(http, './assets/i18n', '.json');
}
@NgModule({
declarations: [MomentDatePipe, NoTagsPipe, SpecialCharsPipe],
exports: [
IonicModule,
MomentDatePipe,
NoTagsPipe,
SpecialCharsPipe,
TranslateModule
],
imports: [
TranslateModule.forRoot({
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [Http]
})
],
providers: [] // MUST NOT have any providers
})
export class SharedModule { }
Noticed that you wrote that one should not use forRoot in shared modules, so I’m aware that this probably is not a good idea, but for the purpose of example…
The translations work when other plugins import the shared module AND it is compiled using JiT. However, it doesn’t seem to work when compiled using AoT - the translations strings dont get translated.
TLDR; can you export a preconfigured TranslateModule from a SharedModule?
Thanks for reading
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Developers - [Question] How do you export TranslateStaticLoader ...
So we have a pretty big project (Ionic 2) with lots of smaller ngModules. We were hoping that you could export a preconfigured...
Read more >Angular translate Pipe could not be found - Stack Overflow
The documentation only suggests having to export TranslateModule when using a SharedModule. · export the module allow using pipe in other modules ...
Read more >Sharing modules - Angular
Creating shared modules allows you to organize and streamline your code. ... OrdersPipe, CommonModule, FormsModule ] }) export class SharedModule { }.
Read more >Ionic view & ngx-translate problem
Hello, i am using ionic2 and the latest ngx translate for multi language ... Translation only works when I do “ionic lab” on...
Read more >ngx-translate Documentation - CodeAndWeb
If you use a SharedModule that you import in multiple other feature modules, you can export the TranslateModule to make sure you don't...
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
This is fixed in 6.0.0 with the new
forChild
method and the updated documentation 😃From the docs
Not sure if we could clarify it even more? The examples are also showing this.
Yes. What happens is that the pre-configuration configures the providers. If a sub-module can’t find an instance in it’s own injector when injecting a service, it will ask the parent if it has an instance for that.