Skip to content

Commit a3e5450

Browse files
committed
fix(material/datepicker): deprecate constructor injection in NativeDateAdapter
1 parent 6f52973 commit a3e5450

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/material/core/datetime/native-date-adapter.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {Platform} from '@angular/cdk/platform';
10-
import {Inject, Injectable, Optional} from '@angular/core';
10+
import {inject, Inject, Injectable, Optional} from '@angular/core';
1111
import {DateAdapter, MAT_DATE_LOCALE} from './date-adapter';
1212

1313
/**
@@ -36,16 +36,26 @@ export class NativeDateAdapter extends DateAdapter<Date> {
3636
*/
3737
useUtcForDisplay: boolean = false;
3838

39+
/** The injected locale. */
40+
private readonly _matDateLocale = inject(MAT_DATE_LOCALE, {optional: true});
41+
3942
constructor(
40-
@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale: string,
43+
/**
44+
* @deprecated Now injected via inject(), param to be removed.
45+
* @breaking-change 14.0.0
46+
*/
47+
@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale?: string,
4148
/**
4249
* @deprecated No longer being used. To be removed.
4350
* @breaking-change 14.0.0
4451
*/
4552
_platform?: Platform,
4653
) {
4754
super();
48-
super.setLocale(matDateLocale);
55+
if (matDateLocale !== undefined) {
56+
this._matDateLocale = matDateLocale;
57+
}
58+
super.setLocale(this._matDateLocale);
4959
}
5060

5161
getYear(date: Date): number {

0 commit comments

Comments
 (0)