Skip to content

Commit 5360899

Browse files
authored
refactor(material/paginator): switch to inject function (#30253)
Switches `mat-paginator` to use the `inject` function now that we've cleaned up the internal usages.
1 parent 8ae1431 commit 5360899

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/material/paginator/paginator.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ import {
1111
ChangeDetectorRef,
1212
Component,
1313
EventEmitter,
14-
Inject,
1514
InjectionToken,
1615
Input,
1716
OnDestroy,
1817
OnInit,
19-
Optional,
2018
Output,
2119
ViewEncapsulation,
2220
booleanAttribute,
@@ -111,6 +109,9 @@ export const MAT_PAGINATOR_DEFAULT_OPTIONS = new InjectionToken<MatPaginatorDefa
111109
imports: [MatFormField, MatSelect, MatOption, MatIconButton, MatTooltip],
112110
})
113111
export class MatPaginator implements OnInit, OnDestroy {
112+
_intl = inject(MatPaginatorIntl);
113+
private _changeDetectorRef = inject(ChangeDetectorRef);
114+
114115
/** If set, styles the "page size" form field with the designated style. */
115116
_formFieldAppearance?: MatFormFieldAppearance;
116117

@@ -198,11 +199,15 @@ export class MatPaginator implements OnInit, OnDestroy {
198199
/** Emits when the paginator is initialized. */
199200
initialized: Observable<void> = this._initializedStream;
200201

201-
constructor(
202-
public _intl: MatPaginatorIntl,
203-
private _changeDetectorRef: ChangeDetectorRef,
204-
@Optional() @Inject(MAT_PAGINATOR_DEFAULT_OPTIONS) defaults?: MatPaginatorDefaultOptions,
205-
) {
202+
/** Inserted by Angular inject() migration for backwards compatibility */
203+
constructor(...args: unknown[]);
204+
205+
constructor() {
206+
const _intl = this._intl;
207+
const defaults = inject<MatPaginatorDefaultOptions>(MAT_PAGINATOR_DEFAULT_OPTIONS, {
208+
optional: true,
209+
});
210+
206211
this._intlChanges = _intl.changes.subscribe(() => this._changeDetectorRef.markForCheck());
207212

208213
if (defaults) {

tools/public_api_guard/material/paginator.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
```ts
66

7-
import { ChangeDetectorRef } from '@angular/core';
87
import { EventEmitter } from '@angular/core';
98
import * as i0 from '@angular/core';
109
import * as i1 from '@angular/material/button';
@@ -34,7 +33,7 @@ export function MAT_PAGINATOR_INTL_PROVIDER_FACTORY(parentIntl: MatPaginatorIntl
3433

3534
// @public
3635
export class MatPaginator implements OnInit, OnDestroy {
37-
constructor(_intl: MatPaginatorIntl, _changeDetectorRef: ChangeDetectorRef, defaults?: MatPaginatorDefaultOptions);
36+
constructor(...args: unknown[]);
3837
protected _buttonClicked(targetIndex: number, isDisabled: boolean): void;
3938
_changePageSize(pageSize: number): void;
4039
color: ThemePalette;
@@ -85,7 +84,7 @@ export class MatPaginator implements OnInit, OnDestroy {
8584
// (undocumented)
8685
static ɵcmp: i0.ɵɵComponentDeclaration<MatPaginator, "mat-paginator", ["matPaginator"], { "color": { "alias": "color"; "required": false; }; "pageIndex": { "alias": "pageIndex"; "required": false; }; "length": { "alias": "length"; "required": false; }; "pageSize": { "alias": "pageSize"; "required": false; }; "pageSizeOptions": { "alias": "pageSizeOptions"; "required": false; }; "hidePageSize": { "alias": "hidePageSize"; "required": false; }; "showFirstLastButtons": { "alias": "showFirstLastButtons"; "required": false; }; "selectConfig": { "alias": "selectConfig"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; }, { "page": "page"; }, never, never, true, never>;
8786
// (undocumented)
88-
static ɵfac: i0.ɵɵFactoryDeclaration<MatPaginator, [null, null, { optional: true; }]>;
87+
static ɵfac: i0.ɵɵFactoryDeclaration<MatPaginator, never>;
8988
}
9089

9190
// @public

0 commit comments

Comments
 (0)