Skip to content

Commit

Permalink
fix(material/datepicker): deprecate constructor injection in NativeDa…
Browse files Browse the repository at this point in the history
…teAdapter (angular#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).
  • Loading branch information
mmalerba authored Aug 17, 2023
1 parent 3fe5c14 commit b423c0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions src/material/core/datetime/native-date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

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

/**
Expand Down Expand Up @@ -36,16 +35,21 @@ export class NativeDateAdapter extends DateAdapter<Date> {
*/
useUtcForDisplay: boolean = false;

/** The injected locale. */
private readonly _matDateLocale = inject(MAT_DATE_LOCALE, {optional: true});

constructor(
@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale: string,
/**
* @deprecated No longer being used. To be removed.
* @breaking-change 14.0.0
* @deprecated Now injected via inject(), param to be removed.
* @breaking-change 18.0.0
*/
_platform?: Platform,
@Optional() @Inject(MAT_DATE_LOCALE) matDateLocale?: string,
) {
super();
super.setLocale(matDateLocale);
if (matDateLocale !== undefined) {
this._matDateLocale = matDateLocale;
}
super.setLocale(this._matDateLocale);
}

getYear(date: Date): number {
Expand Down
6 changes: 3 additions & 3 deletions tools/public_api_guard/material/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ export function mixinTabIndex<T extends _AbstractConstructor<CanDisable>>(base:

// @public
export class NativeDateAdapter extends DateAdapter<Date> {
constructor(matDateLocale: string,
_platform?: Platform);
constructor(
matDateLocale?: string);
// (undocumented)
addCalendarDays(date: Date, days: number): Date;
// (undocumented)
Expand Down Expand Up @@ -479,7 +479,7 @@ export class NativeDateAdapter extends DateAdapter<Date> {
// @deprecated (undocumented)
useUtcForDisplay: boolean;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<NativeDateAdapter, [{ optional: true; }, null]>;
static ɵfac: i0.ɵɵFactoryDeclaration<NativeDateAdapter, [{ optional: true; }]>;
// (undocumented)
static ɵprov: i0.ɵɵInjectableDeclaration<NativeDateAdapter>;
}
Expand Down

0 comments on commit b423c0e

Please sign in to comment.