-
Notifications
You must be signed in to change notification settings - Fork 6.8k
DateAdapter: issues with setLocale(..) in main vs. lazy loaded module #12891
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
The problem is that the A possible workaround is to just make sure that the I personally think that it's reasonable to have multiple nested |
Yes sure, that's why usually you have the
For sure this needs to be documented better 😉.
🤔 hmm...not sure. Currently thinking about that. How would that work. Like when registered in plain normal modules, there would be just 1 global singleton instance anyway. The "multiple" ones only happens in the lazy loaded modules case as I mentioned, as that one will get its own DI container. To have different instances within my same app, I'd expect to re-registering the |
Yeah, if we decide to only have one instance of a Regarding multiple So I don't think it's right to always assume that the
That would work, but not sure if we want to go this way API-wise. Let's see what @mmalerba thinks. |
Actually I need to take back what I said. Only in lazy-loaded modules, the providers from the app root can be isolated. So my argument that people intentionally extract stuff into external feature modules in order to have their own instance of the Quote from the docs (https://angular.io/guide/providers).
Good catch @juristr. Thanks |
guys i cant solve this issue :( |
have you try calling |
Yap that helps. But I moved
|
"@angular/material": "14.2.4" |
I found that calling setLocale in a shared module only works, if it's executed right away. It does not work anymore in the translate onLangChange listener. |
Uh oh!
There was an error while loading. Please reload this page.
Bug, feature request, or proposal:
Bug (probably, otherwise docs need to be updated to clarify this behavior).
What is the expected behavior?
I expect the entire application to be in a certain locale, thus it should be enough to set it once using the DateAdapter's
setLocale(..)
.What is the current behavior?
Apparently the
DateAdapter
is not a single instance, but rather lazy modules get their own instance. As a result, setting the locale (like in theapp.component.ts
might not work (as one expects) when loading some components within a lazy loaded module (via routing).What are the steps to reproduce?
Here's a Stackblitz to reproduce the issue: https://stackblitz.com/edit/angular-material-datepicker-locale?file=src%2Fapp%2Fapp.component.ts
/test
route. Both,app.module
andlazy.module
importSharedModule
which imports the Material stuff.That makes me think there are 2 instances of the
DateAdapter
, one for the lazy module and one for the app module.What is the use-case or motivation for changing an existing behavior?
Usually the locale is very much related to the application language. In most cases you load the user profile when the app starts and based on his settings, cookies or whatever, you set the language and locale respectively. Similarly at the same point you also want to adjust other components' locales such as the Material Datepicker.
The current behavior however is misleading, as one might expect that setting the locale on the
DateAdapter
object should automatically adjust them for all datepickers. Due to the bug that is not the case for lazy loaded modules however.Which versions of Angular, Material, OS, TypeScript, browsers are affected?
The text was updated successfully, but these errors were encountered: