-
-
Notifications
You must be signed in to change notification settings - Fork 588
Question Regarding Lazy Loading with new Angular 17+ API #1538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hey @Galileon-venta. there is (yet ; ) no official way to support it and if wished I could do a PR, but here is a way you could deal with lazy loading in Angular 17+ 1. Create a resolverexport const HomeTranslationsResolver: ResolveFn<void> = async () => {
const http = inject(HttpClient);
const translate = inject(TranslateService);
const loader = new TranslateHttpLoader(http, './assets/i18n/home/', '.json');
loader.getTranslation(translate.currentLang).subscribe((translations) => {
translate.setTranslation(translate.currentLang, translations, true);
// True: merges all files together
// False: Replace the files
})
}; 2. use it int he route where you'd need it.// ...
{
path: 'home',
resolve: {
HomeTranslationsResolver,
},
loadComponent: () => /...
} Please, close this issue if it does answer your question ; ) Happy coding <3 Note: HttpBackendIf this PRs get accepted, you'll have to use @CodeAndWeb Should I create a new resolver ?
|
Interesting approach; Without testing it in actual code, it seems to me that this would not include live language change possibilities but rather would require a page reload while changing the language. I assume it's not that hard to add a subscription for the language change here, but it offers potential problems to keep in mind when it comes to clean-up. Would love to see an official suggestion to reduce the possible varieties of implementation here. |
@Galileon-venta good catch, I'll analyse the code, modify it and see if I can get a PR to add official support for this kind of resolver |
With Standalone Components are there any resources regarding lazy loading additional Translations for lazy loaded Components? Is it still only possible using importProvidersFrom()?
The text was updated successfully, but these errors were encountered: