Skip to content

Commit e397ecb

Browse files
authored
fix(cdk/table): remove string-based DI tokens (angular#32677)
String-based DI was accidentally supported, but since the introduction of the `inject` function it isn't supported officially in the types anymore. These changes remove our only usage so we don't get broken if support is removed in the future.
1 parent ec384a3 commit e397ecb

File tree

5 files changed

+8
-25
lines changed

5 files changed

+8
-25
lines changed

goldens/material/sort/index.api.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,13 @@ export class MatSortHeader implements MatSortable, OnDestroy, OnInit, AfterViewI
8181
// (undocumented)
8282
protected _animationsDisabled: boolean;
8383
arrowPosition: SortHeaderArrowPosition;
84-
// (undocumented)
85-
_columnDef: MatSortHeaderColumnDef | null;
8684
disableClear: boolean;
8785
disabled: boolean;
8886
_getAriaSortAttribute(): "none" | "ascending" | "descending";
8987
// (undocumented)
9088
_handleKeydown(event: KeyboardEvent): void;
9189
id: string;
9290
// (undocumented)
93-
_intl: MatSortHeaderIntl;
94-
// (undocumented)
9591
_isDisabled(): boolean;
9692
_isSorted(): boolean;
9793
// (undocumented)
@@ -107,7 +103,7 @@ export class MatSortHeader implements MatSortable, OnDestroy, OnInit, AfterViewI
107103
protected _recentlyCleared: i0.WritableSignal<SortDirection | null>;
108104
_renderArrow(): boolean;
109105
// (undocumented)
110-
_sort: MatSort;
106+
protected _sort: MatSort;
111107
get sortActionDescription(): string;
112108
set sortActionDescription(value: string);
113109
start: SortDirection;

src/cdk/table/cell.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ export class CdkFooterCellDef implements CellDef {
7272
* Column definition for the CDK table.
7373
* Defines a set of cells available for a table column.
7474
*/
75-
@Directive({
76-
selector: '[cdkColumnDef]',
77-
providers: [{provide: 'MAT_SORT_HEADER_COLUMN_DEF', useExisting: CdkColumnDef}],
78-
})
75+
@Directive({selector: '[cdkColumnDef]'})
7976
export class CdkColumnDef implements CanStick {
8077
_table? = inject(CDK_TABLE, {optional: true});
8178

src/material/sort/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ ng_project(
8282
"//src:dev_mode_types",
8383
"//src/cdk/a11y",
8484
"//src/cdk/keycodes",
85+
"//src/cdk/table",
8586
"//src/material/core",
8687
],
8788
)

src/material/sort/sort-header.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import {
2222
signal,
2323
ChangeDetectorRef,
2424
} from '@angular/core';
25+
import {_CdkPrivateStyleLoader} from '@angular/cdk/private';
26+
import {CdkColumnDef} from '@angular/cdk/table';
2527
import {merge, Subscription} from 'rxjs';
2628
import {
2729
MAT_SORT_DEFAULT_OPTIONS,
@@ -32,8 +34,6 @@ import {
3234
} from './sort';
3335
import {SortDirection} from './sort-direction';
3436
import {getSortHeaderNotContainedWithinSortError} from './sort-errors';
35-
import {MatSortHeaderIntl} from './sort-header-intl';
36-
import {_CdkPrivateStyleLoader} from '@angular/cdk/private';
3737
import {_animationsDisabled, _StructuralStylesLoader} from '../core';
3838

3939
/**
@@ -60,11 +60,6 @@ export interface ArrowViewStateTransition {
6060
toState?: ArrowViewState;
6161
}
6262

63-
/** Column definition associated with a `MatSortHeader`. */
64-
interface MatSortHeaderColumnDef {
65-
name: string;
66-
}
67-
6863
/**
6964
* Applies sorting behavior (click to change sort) and styles to an element, including an
7065
* arrow to display the current sort direction.
@@ -91,11 +86,8 @@ interface MatSortHeaderColumnDef {
9186
changeDetection: ChangeDetectionStrategy.OnPush,
9287
})
9388
export class MatSortHeader implements MatSortable, OnDestroy, OnInit, AfterViewInit {
94-
_intl = inject(MatSortHeaderIntl);
95-
_sort = inject(MatSort, {optional: true})!;
96-
_columnDef = inject<MatSortHeaderColumnDef>('MAT_SORT_HEADER_COLUMN_DEF' as any, {
97-
optional: true,
98-
});
89+
protected _sort = inject(MatSort, {optional: true})!;
90+
private _columnDef = inject(CdkColumnDef, {optional: true});
9991
private _changeDetectorRef = inject(ChangeDetectorRef);
10092
private _focusMonitor = inject(FocusMonitor);
10193
private _elementRef = inject<ElementRef<HTMLElement>>(ElementRef);

src/material/table/cell.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ export class MatFooterCellDef extends CdkFooterCellDef {}
5353
*/
5454
@Directive({
5555
selector: '[matColumnDef]',
56-
providers: [
57-
{provide: CdkColumnDef, useExisting: MatColumnDef},
58-
{provide: 'MAT_SORT_HEADER_COLUMN_DEF', useExisting: MatColumnDef},
59-
],
56+
providers: [{provide: CdkColumnDef, useExisting: MatColumnDef}],
6057
})
6158
export class MatColumnDef extends CdkColumnDef {
6259
/** Unique name for this column. */

0 commit comments

Comments
 (0)