-
Notifications
You must be signed in to change notification settings - Fork 6.8k
docs(datepicker): need better guidance for use with lazy loaded modules #18970
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
i guess it's not a datepicker intl bug, lazy loaded modules have their own injector, you do need to override the intl provider |
I updated my description with link to source on stackblitz. You can see there that I provide my MatDatepickerIntl. I think that problem is in implementation of https://github.com/angular/components/blob/master/src/material/datepicker/datepicker-module.ts |
ok i got the point, but the problem is the scope of the provider override. since lazy modules have different injectors, the override has no effect.. so you're proposing to change the MatDatepickerIntl to an injection token with a default value |
I do think the material.angular.io docs need to do a better job discussing how to use the datepicker with lazy loaded modules. I'll update the title and use this issue to track that |
If MatDatepickerIntl was meant to be a singleton than IMO this is a bug. It already provides itself in the root injector, I think it shouldn't be listed in MatDatepickerModule's providers. |
This could be a solution, however Paginator, Sort and Stepper are using a different approach, and that works properly. |
Current implementation guarantees that lazy loaded module behaves the same, no matter in what application it is imported. I like the idea, although I do not think that there are many real world scenarios for this level of reusability. I agree this should be documented bettter and I agree this seem inconsistent with other Material components. I see two solutions that can be used in applications:
|
Angular 14 release with standalone component can solve the problem, I think |
hi I created deep insight about datepicker and standalone component in this post https://dev.to/hiepxanh/angular-14-standalone-component-help-reduce-bundle-size-and-the-story-behind-you-may-not-know-1f44 https://gist.github.com/hiepxanh/1306f075b2478e62133473d8cfaca537 @ViewChild('datepickerTemplate', { read: ViewContainerRef }) datepickerTemplate!: ViewContainerRef;
constructor(private fb: FormBuilder) {}
async loadComponent() {
const { DatepickerAtom } = await import('../../atoms/datepicker/datepicker.atom');
const componentRef = this.datepickerTemplate.createComponent(DatepickerAtom);
const dobControl = this.optionalForm.get('dob');
if (dobControl) {
componentRef.instance.dob = dobControl;
}
}
ngOnInit(): void {
this.loadComponent();
} |
In angular 15 it still doesn't work |
Uh oh!
There was an error while loading. Please reload this page.
Reproduction
I created here MyIntl class and I set there only text for calendar open button.
https://angular-material-datepicker-intl.stackblitz.io
https://stackblitz.com/edit/angular-material-datepicker-intl
Steps to reproduce:
Expected Behavior
I expected that if I provide my custom implementation of MatDatepickerIntl in AppModule it will work also for all lazy loaded modules.
For example MatPaginator works that way.
Actual Behavior
Custom implementation of MatDatepickerIntl is not provided in lazy loaded modules
Environment
The text was updated successfully, but these errors were encountered: