Skip to content

Commit 8078eb8

Browse files
authored
refactor(multiple): remove usages of the deprecated signature of inject (#25817)
Cleans up the usages of the deprecated signature of the `inject` function that were passing in `InjectFlags` instead of an object literal.
1 parent 8fb804b commit 8078eb8

File tree

8 files changed

+18
-32
lines changed

8 files changed

+18
-32
lines changed

src/cdk/listbox/listbox.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
ElementRef,
1515
forwardRef,
1616
inject,
17-
InjectFlags,
1817
Input,
1918
OnDestroy,
2019
Output,
@@ -431,7 +430,7 @@ export class CdkListbox<T = unknown>
431430
);
432431

433432
/** The directionality of the page. */
434-
private readonly _dir = inject(Directionality, InjectFlags.Optional);
433+
private readonly _dir = inject(Directionality, {optional: true});
435434

436435
/** A predicate that skips disabled options. */
437436
private readonly _skipDisabledPredicate = (option: CdkOption<T>) => option.disabled;

src/cdk/menu/context-menu-trigger.ts

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

9-
import {Directive, inject, Injectable, InjectFlags, Input, OnDestroy} from '@angular/core';
9+
import {Directive, inject, Injectable, Input, OnDestroy} from '@angular/core';
1010
import {Directionality} from '@angular/cdk/bidi';
1111
import {
1212
FlexibleConnectedPositionStrategy,
@@ -77,7 +77,7 @@ export class CdkContextMenuTrigger extends CdkMenuTriggerBase implements OnDestr
7777
private readonly _overlay = inject(Overlay);
7878

7979
/** The directionality of the page. */
80-
private readonly _directionality = inject(Directionality, InjectFlags.Optional);
80+
private readonly _directionality = inject(Directionality, {optional: true});
8181

8282
/** The app's context menu tracking registry */
8383
private readonly _contextMenuTracker = inject(ContextMenuTracker);

src/cdk/menu/menu-base.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
Directive,
1414
ElementRef,
1515
inject,
16-
InjectFlags,
1716
Input,
1817
NgZone,
1918
OnDestroy,
@@ -63,10 +62,10 @@ export abstract class CdkMenuBase
6362
readonly menuStack: MenuStack = inject(MENU_STACK);
6463

6564
/** The menu aim service used by this menu. */
66-
protected readonly menuAim = inject(MENU_AIM, InjectFlags.Optional | InjectFlags.Self);
65+
protected readonly menuAim = inject(MENU_AIM, {optional: true, self: true});
6766

6867
/** The directionality (text direction) of the current page. */
69-
protected readonly dir = inject(Directionality, InjectFlags.Optional);
68+
protected readonly dir = inject(Directionality, {optional: true});
7069

7170
/** The id of the menu's host element. */
7271
@Input() id = `cdk-menu-${nextId++}`;

src/cdk/menu/menu-item.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
ElementRef,
1212
EventEmitter,
1313
inject,
14-
InjectFlags,
1514
Input,
1615
NgZone,
1716
OnDestroy,
@@ -50,7 +49,7 @@ import {MENU_AIM, Toggler} from './menu-aim';
5049
})
5150
export class CdkMenuItem implements FocusableOption, FocusableElement, Toggler, OnDestroy {
5251
/** The directionality (text direction) of the current page. */
53-
protected readonly _dir = inject(Directionality, InjectFlags.Optional);
52+
protected readonly _dir = inject(Directionality, {optional: true});
5453

5554
/** The menu's native DOM host element. */
5655
readonly _elementRef: ElementRef<HTMLElement> = inject(ElementRef);
@@ -59,16 +58,16 @@ export class CdkMenuItem implements FocusableOption, FocusableElement, Toggler,
5958
protected _ngZone = inject(NgZone);
6059

6160
/** The menu aim service used by this menu. */
62-
private readonly _menuAim = inject(MENU_AIM, InjectFlags.Optional);
61+
private readonly _menuAim = inject(MENU_AIM, {optional: true});
6362

6463
/** The stack of menus this menu belongs to. */
6564
private readonly _menuStack = inject(MENU_STACK);
6665

6766
/** The parent menu in which this menuitem resides. */
68-
private readonly _parentMenu = inject(CDK_MENU, InjectFlags.Optional);
67+
private readonly _parentMenu = inject(CDK_MENU, {optional: true});
6968

7069
/** Reference to the CdkMenuItemTrigger directive if one is added to the same element */
71-
private readonly _menuTrigger = inject(CdkMenuTrigger, InjectFlags.Optional | InjectFlags.Self);
70+
private readonly _menuTrigger = inject(CdkMenuTrigger, {optional: true, self: true});
7271

7372
/** Whether the CdkMenuItem is disabled - defaults to false */
7473
@Input('cdkMenuItemDisabled')

src/cdk/menu/menu-trigger.ts

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

9-
import {Directive, ElementRef, inject, InjectFlags, NgZone, OnDestroy} from '@angular/core';
9+
import {Directive, ElementRef, inject, NgZone, OnDestroy} from '@angular/core';
1010
import {Directionality} from '@angular/cdk/bidi';
1111
import {
1212
ConnectedPosition,
@@ -73,13 +73,13 @@ export class CdkMenuTrigger extends CdkMenuTriggerBase implements OnDestroy {
7373
private readonly _ngZone = inject(NgZone);
7474

7575
/** The parent menu this trigger belongs to. */
76-
private readonly _parentMenu = inject(CDK_MENU, InjectFlags.Optional);
76+
private readonly _parentMenu = inject(CDK_MENU, {optional: true});
7777

7878
/** The menu aim service used by this menu. */
79-
private readonly _menuAim = inject(MENU_AIM, InjectFlags.Optional);
79+
private readonly _menuAim = inject(MENU_AIM, {optional: true});
8080

8181
/** The directionality of the page. */
82-
private readonly _directionality = inject(Directionality, InjectFlags.Optional);
82+
private readonly _directionality = inject(Directionality, {optional: true});
8383

8484
constructor() {
8585
super();

src/cdk/menu/menu.ts

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

9-
import {
10-
AfterContentInit,
11-
Directive,
12-
EventEmitter,
13-
inject,
14-
InjectFlags,
15-
OnDestroy,
16-
Output,
17-
} from '@angular/core';
9+
import {AfterContentInit, Directive, EventEmitter, inject, OnDestroy, Output} from '@angular/core';
1810
import {ESCAPE, hasModifierKey, LEFT_ARROW, RIGHT_ARROW, TAB} from '@angular/cdk/keycodes';
1911
import {takeUntil} from 'rxjs/operators';
2012
import {CdkMenuGroup} from './menu-group';
@@ -46,7 +38,7 @@ import {CdkMenuBase} from './menu-base';
4638
],
4739
})
4840
export class CdkMenu extends CdkMenuBase implements AfterContentInit, OnDestroy {
49-
private _parentTrigger = inject(MENU_TRIGGER, InjectFlags.Optional);
41+
private _parentTrigger = inject(MENU_TRIGGER, {optional: true});
5042

5143
/** Event emitted when the menu is closed. */
5244
@Output() readonly closed: EventEmitter<void> = new EventEmitter();

src/material/datepicker/date-range-input-parts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ abstract class MatDateRangeInputPartBase<D>
8989
protected abstract override _assignValueToModel(value: D | null): void;
9090
protected abstract override _getValueFromModel(modelValue: DateRange<D>): D | null;
9191

92-
protected readonly _dir = inject(Directionality, InjectFlags.Optional);
92+
protected readonly _dir = inject(Directionality, {optional: true});
9393

9494
constructor(
9595
@Inject(MAT_DATE_RANGE_INPUT_PARENT) public _rangeInput: MatDateRangeInputParent<D>,

src/material/legacy-input/input.ts

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

9-
import {Directive, inject, InjectFlags} from '@angular/core';
9+
import {Directive, inject} from '@angular/core';
1010
import {MatInput as BaseMatInput} from '@angular/material/input';
1111
import {
1212
MatLegacyFormFieldControl,
@@ -44,10 +44,7 @@ import {
4444
providers: [{provide: MatLegacyFormFieldControl, useExisting: MatLegacyInput}],
4545
})
4646
export class MatLegacyInput extends BaseMatInput {
47-
private _legacyFormField = inject<MatLegacyFormField>(
48-
MAT_LEGACY_FORM_FIELD,
49-
InjectFlags.Optional,
50-
);
47+
private _legacyFormField = inject<MatLegacyFormField>(MAT_LEGACY_FORM_FIELD, {optional: true});
5148

5249
protected override _getPlaceholder() {
5350
// If we're hiding the native placeholder, it should also be cleared from the DOM, otherwise

0 commit comments

Comments
 (0)