Skip to content

Commit b423c0e

Browse files
authored
fix(material/datepicker): deprecate constructor injection in NativeDateAdapter (#26144)
BREAKING CHANGE: `NativeDateAdapter` no longer takes `Platform` in its constructor. It also now uses the `inject` function, and therefore cannot be instantiated directly (must go through Angular's DI system instead).
1 parent 3fe5c14 commit b423c0e

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

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

1312
/**
@@ -36,16 +35,21 @@ export class NativeDateAdapter extends DateAdapter<Date> {
3635
*/
3736
useUtcForDisplay: boolean = false;
3837

38+
/** The injected locale. */
39+
private readonly _matDateLocale = inject(MAT_DATE_LOCALE, {optional: true});
40+
3941
constructor(
40-
@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale: string,
4142
/**
42-
* @deprecated No longer being used. To be removed.
43-
* @breaking-change 14.0.0
43+
* @deprecated Now injected via inject(), param to be removed.
44+
* @breaking-change 18.0.0
4445
*/
45-
_platform?: Platform,
46+
@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale?: string,
4647
) {
4748
super();
48-
super.setLocale(matDateLocale);
49+
if (matDateLocale !== undefined) {
50+
this._matDateLocale = matDateLocale;
51+
}
52+
super.setLocale(this._matDateLocale);
4953
}
5054

5155
getYear(date: Date): number {

tools/public_api_guard/material/core.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ export function mixinTabIndex<T extends _AbstractConstructor<CanDisable>>(base:
429429

430430
// @public
431431
export class NativeDateAdapter extends DateAdapter<Date> {
432-
constructor(matDateLocale: string,
433-
_platform?: Platform);
432+
constructor(
433+
matDateLocale?: string);
434434
// (undocumented)
435435
addCalendarDays(date: Date, days: number): Date;
436436
// (undocumented)
@@ -479,7 +479,7 @@ export class NativeDateAdapter extends DateAdapter<Date> {
479479
// @deprecated (undocumented)
480480
useUtcForDisplay: boolean;
481481
// (undocumented)
482-
static ɵfac: i0.ɵɵFactoryDeclaration<NativeDateAdapter, [{ optional: true; }, null]>;
482+
static ɵfac: i0.ɵɵFactoryDeclaration<NativeDateAdapter, [{ optional: true; }]>;
483483
// (undocumented)
484484
static ɵprov: i0.ɵɵInjectableDeclaration<NativeDateAdapter>;
485485
}

0 commit comments

Comments
 (0)