diff --git a/src/cdk/a11y/a11y-module.ts b/src/cdk/a11y/a11y-module.ts index 58e478bc9779..548ab1be880b 100644 --- a/src/cdk/a11y/a11y-module.ts +++ b/src/cdk/a11y/a11y-module.ts @@ -7,7 +7,7 @@ */ import {ObserversModule} from '@angular/cdk/observers'; -import {NgModule} from '@angular/core'; +import {NgModule, inject} from '@angular/core'; import {CdkMonitorFocus} from './focus-monitor/focus-monitor'; import {CdkTrapFocus} from './focus-trap/focus-trap'; import {HighContrastModeDetector} from './high-contrast-mode/high-contrast-mode-detector'; @@ -18,7 +18,7 @@ import {CdkAriaLive} from './live-announcer/live-announcer'; exports: [CdkAriaLive, CdkTrapFocus, CdkMonitorFocus], }) export class A11yModule { - constructor(highContrastModeDetector: HighContrastModeDetector) { - highContrastModeDetector._applyBodyHighContrastModeCssClasses(); + constructor() { + inject(HighContrastModeDetector)._applyBodyHighContrastModeCssClasses(); } } diff --git a/src/cdk/a11y/aria-describer/aria-describer.spec.ts b/src/cdk/a11y/aria-describer/aria-describer.spec.ts index c5ec92b8b89a..ebb74d1ff8dc 100644 --- a/src/cdk/a11y/aria-describer/aria-describer.spec.ts +++ b/src/cdk/a11y/aria-describer/aria-describer.spec.ts @@ -1,7 +1,7 @@ import {A11yModule, CDK_DESCRIBEDBY_HOST_ATTRIBUTE} from '../index'; import {AriaDescriber} from './aria-describer'; import {ComponentFixture, TestBed} from '@angular/core/testing'; -import {Component, ElementRef, ViewChild, Provider} from '@angular/core'; +import {Component, ElementRef, ViewChild, Provider, inject} from '@angular/core'; describe('AriaDescriber', () => { let ariaDescriber: AriaDescriber; @@ -404,6 +404,8 @@ function expectMessage(el: Element, message: string) { imports: [A11yModule], }) class TestApp { + ariaDescriber = inject(AriaDescriber); + @ViewChild('element1') _element1: ElementRef; get element1(): Element { return this._element1.nativeElement; @@ -423,6 +425,4 @@ class TestApp { get element4(): Element { return this._element4.nativeElement; } - - constructor(public ariaDescriber: AriaDescriber) {} } diff --git a/src/cdk/a11y/aria-describer/aria-describer.ts b/src/cdk/a11y/aria-describer/aria-describer.ts index 47563593c78c..64166543f497 100644 --- a/src/cdk/a11y/aria-describer/aria-describer.ts +++ b/src/cdk/a11y/aria-describer/aria-describer.ts @@ -7,7 +7,7 @@ */ import {DOCUMENT} from '@angular/common'; -import {Inject, Injectable, OnDestroy, APP_ID, inject} from '@angular/core'; +import {Injectable, OnDestroy, APP_ID, inject} from '@angular/core'; import {Platform} from '@angular/cdk/platform'; import {addAriaReferencedId, getAriaReferenceIds, removeAriaReferencedId} from './aria-reference'; @@ -54,7 +54,8 @@ let nextId = 0; */ @Injectable({providedIn: 'root'}) export class AriaDescriber implements OnDestroy { - private _document: Document; + private _platform = inject(Platform); + private _document = inject(DOCUMENT); /** Map of all registered message elements that have been placed into the document. */ private _messageRegistry = new Map(); @@ -65,15 +66,9 @@ export class AriaDescriber implements OnDestroy { /** Unique ID for the service. */ private readonly _id = `${nextId++}`; - constructor( - @Inject(DOCUMENT) _document: any, - /** - * @deprecated To be turned into a required parameter. - * @breaking-change 14.0.0 - */ - private _platform?: Platform, - ) { - this._document = _document; + constructor(...args: unknown[]); + + constructor() { this._id = inject(APP_ID) + '-' + nextId++; } diff --git a/src/cdk/a11y/focus-monitor/focus-monitor.ts b/src/cdk/a11y/focus-monitor/focus-monitor.ts index b22dbc458e55..1dc6091c0352 100644 --- a/src/cdk/a11y/focus-monitor/focus-monitor.ts +++ b/src/cdk/a11y/focus-monitor/focus-monitor.ts @@ -16,14 +16,13 @@ import { Directive, ElementRef, EventEmitter, - Inject, Injectable, InjectionToken, NgZone, OnDestroy, - Optional, Output, AfterViewInit, + inject, } from '@angular/core'; import {Observable, of as observableOf, Subject, Subscription} from 'rxjs'; import {takeUntil} from 'rxjs/operators'; @@ -85,6 +84,10 @@ const captureEventListenerOptions = normalizePassiveListenerOptions({ /** Monitors mouse and keyboard events to determine the cause of focus events. */ @Injectable({providedIn: 'root'}) export class FocusMonitor implements OnDestroy { + private _ngZone = inject(NgZone); + private _platform = inject(Platform); + private readonly _inputModalityDetector = inject(InputModalityDetector); + /** The focus origin that the next focus event is a result of. */ private _origin: FocusOrigin = null; @@ -138,20 +141,18 @@ export class FocusMonitor implements OnDestroy { }; /** Used to reference correct document/window */ - protected _document?: Document; + protected _document? = inject(DOCUMENT, {optional: true}); /** Subject for stopping our InputModalityDetector subscription. */ private readonly _stopInputModalityDetector = new Subject(); - constructor( - private _ngZone: NgZone, - private _platform: Platform, - private readonly _inputModalityDetector: InputModalityDetector, - /** @breaking-change 11.0.0 make document required */ - @Optional() @Inject(DOCUMENT) document: any | null, - @Optional() @Inject(FOCUS_MONITOR_DEFAULT_OPTIONS) options: FocusMonitorOptions | null, - ) { - this._document = document; + constructor(...args: unknown[]); + + constructor() { + const options = inject(FOCUS_MONITOR_DEFAULT_OPTIONS, { + optional: true, + }); + this._detectionMode = options?.detectionMode || FocusMonitorDetectionMode.IMMEDIATE; } /** @@ -619,15 +620,16 @@ export class FocusMonitor implements OnDestroy { standalone: true, }) export class CdkMonitorFocus implements AfterViewInit, OnDestroy { + private _elementRef = inject>(ElementRef); + private _focusMonitor = inject(FocusMonitor); + private _monitorSubscription: Subscription; private _focusOrigin: FocusOrigin = null; @Output() readonly cdkFocusChange = new EventEmitter(); - constructor( - private _elementRef: ElementRef, - private _focusMonitor: FocusMonitor, - ) {} + constructor(...args: unknown[]); + constructor() {} get focusOrigin(): FocusOrigin { return this._focusOrigin; diff --git a/src/cdk/a11y/focus-trap/configurable-focus-trap-factory.ts b/src/cdk/a11y/focus-trap/configurable-focus-trap-factory.ts index dcbad3e10dbc..60966b8bdbbf 100644 --- a/src/cdk/a11y/focus-trap/configurable-focus-trap-factory.ts +++ b/src/cdk/a11y/focus-trap/configurable-focus-trap-factory.ts @@ -7,7 +7,7 @@ */ import {DOCUMENT} from '@angular/common'; -import {Inject, Injectable, Injector, NgZone, Optional, inject} from '@angular/core'; +import {Injectable, Injector, NgZone, inject} from '@angular/core'; import {InteractivityChecker} from '../interactivity-checker/interactivity-checker'; import {ConfigurableFocusTrap} from './configurable-focus-trap'; import {ConfigurableFocusTrapConfig} from './configurable-focus-trap-config'; @@ -18,21 +18,22 @@ import {FocusTrapManager} from './focus-trap-manager'; /** Factory that allows easy instantiation of configurable focus traps. */ @Injectable({providedIn: 'root'}) export class ConfigurableFocusTrapFactory { - private _document: Document; + private _checker = inject(InteractivityChecker); + private _ngZone = inject(NgZone); + private _focusTrapManager = inject(FocusTrapManager); + + private _document = inject(DOCUMENT); private _inertStrategy: FocusTrapInertStrategy; private readonly _injector = inject(Injector); - constructor( - private _checker: InteractivityChecker, - private _ngZone: NgZone, - private _focusTrapManager: FocusTrapManager, - @Inject(DOCUMENT) _document: any, - @Optional() @Inject(FOCUS_TRAP_INERT_STRATEGY) _inertStrategy?: FocusTrapInertStrategy, - ) { - this._document = _document; + constructor(...args: unknown[]); + + constructor() { + const inertStrategy = inject(FOCUS_TRAP_INERT_STRATEGY, {optional: true}); + // TODO split up the strategies into different modules, similar to DateAdapter. - this._inertStrategy = _inertStrategy || new EventListenerFocusTrapInertStrategy(); + this._inertStrategy = inertStrategy || new EventListenerFocusTrapInertStrategy(); } /** diff --git a/src/cdk/a11y/focus-trap/configurable-focus-trap.spec.ts b/src/cdk/a11y/focus-trap/configurable-focus-trap.spec.ts index 1fd923f9ecd4..dfecc2cc111e 100644 --- a/src/cdk/a11y/focus-trap/configurable-focus-trap.spec.ts +++ b/src/cdk/a11y/focus-trap/configurable-focus-trap.spec.ts @@ -1,4 +1,12 @@ -import {AfterViewInit, Component, ElementRef, Type, ViewChild, Provider} from '@angular/core'; +import { + AfterViewInit, + Component, + ElementRef, + Type, + ViewChild, + Provider, + inject, +} from '@angular/core'; import {ComponentFixture, TestBed} from '@angular/core/testing'; import { A11yModule, @@ -110,12 +118,12 @@ function createComponent( standalone: true, }) class SimpleFocusTrap implements AfterViewInit { + private _focusTrapFactory = inject(ConfigurableFocusTrapFactory); + @ViewChild('focusTrapElement') focusTrapElement!: ElementRef; focusTrap: ConfigurableFocusTrap; - constructor(private _focusTrapFactory: ConfigurableFocusTrapFactory) {} - ngAfterViewInit() { this.focusTrap = this._focusTrapFactory.create(this.focusTrapElement.nativeElement); } diff --git a/src/cdk/a11y/focus-trap/event-listener-inert-strategy.spec.ts b/src/cdk/a11y/focus-trap/event-listener-inert-strategy.spec.ts index 6434cc3f51e5..f31bb3a1995f 100644 --- a/src/cdk/a11y/focus-trap/event-listener-inert-strategy.spec.ts +++ b/src/cdk/a11y/focus-trap/event-listener-inert-strategy.spec.ts @@ -1,4 +1,12 @@ -import {AfterViewInit, Component, ElementRef, Provider, Type, ViewChild} from '@angular/core'; +import { + AfterViewInit, + Component, + ElementRef, + Provider, + Type, + ViewChild, + inject, +} from '@angular/core'; import {ComponentFixture, TestBed, fakeAsync, flush} from '@angular/core/testing'; import {patchElementFocus} from '../../testing/private'; import { @@ -80,6 +88,8 @@ function createComponent( standalone: true, }) class SimpleFocusTrap implements AfterViewInit { + private _focusTrapFactory = inject(ConfigurableFocusTrapFactory); + @ViewChild('focusTrapElement') focusTrapElement!: ElementRef; @ViewChild('outsideFocusable') outsideFocusableElement!: ElementRef; @ViewChild('firstFocusable') firstFocusableElement!: ElementRef; @@ -91,8 +101,6 @@ class SimpleFocusTrap implements AfterViewInit { // the `document.activeElement`, we need to keep track of it here. activeElement: Element | null; - constructor(private _focusTrapFactory: ConfigurableFocusTrapFactory) {} - ngAfterViewInit() { // Ensure consistent focus timing across browsers. [ diff --git a/src/cdk/a11y/focus-trap/focus-trap.spec.ts b/src/cdk/a11y/focus-trap/focus-trap.spec.ts index 96b1078f32e3..4ae11ebd29ca 100644 --- a/src/cdk/a11y/focus-trap/focus-trap.spec.ts +++ b/src/cdk/a11y/focus-trap/focus-trap.spec.ts @@ -6,6 +6,7 @@ import { ViewChild, ViewContainerRef, ViewEncapsulation, + inject as inject_1, } from '@angular/core'; import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing'; import {By} from '@angular/platform-browser'; @@ -481,8 +482,8 @@ class FocusTrapWithoutFocusableElements { imports: [A11yModule, PortalModule], }) class FocusTrapInsidePortal { + viewContainerRef = inject_1(ViewContainerRef); + @ViewChild('template') template: TemplateRef; @ViewChild(CdkPortalOutlet) portalOutlet: CdkPortalOutlet; - - constructor(public viewContainerRef: ViewContainerRef) {} } diff --git a/src/cdk/a11y/focus-trap/focus-trap.ts b/src/cdk/a11y/focus-trap/focus-trap.ts index 887beee6b53a..9d2bf4bfa05a 100644 --- a/src/cdk/a11y/focus-trap/focus-trap.ts +++ b/src/cdk/a11y/focus-trap/focus-trap.ts @@ -13,7 +13,6 @@ import { Directive, DoCheck, ElementRef, - Inject, Injectable, Injector, Input, @@ -372,16 +371,14 @@ export class FocusTrap { */ @Injectable({providedIn: 'root'}) export class FocusTrapFactory { - private _document: Document; + private _checker = inject(InteractivityChecker); + private _ngZone = inject(NgZone); + + private _document = inject(DOCUMENT); private _injector = inject(Injector); - constructor( - private _checker: InteractivityChecker, - private _ngZone: NgZone, - @Inject(DOCUMENT) _document: any, - ) { - this._document = _document; - } + constructor(...args: unknown[]); + constructor() {} /** * Creates a focus-trapped region around the given element. @@ -409,6 +406,9 @@ export class FocusTrapFactory { standalone: true, }) export class CdkTrapFocus implements OnDestroy, AfterContentInit, OnChanges, DoCheck { + private _elementRef = inject>(ElementRef); + private _focusTrapFactory = inject(FocusTrapFactory); + /** Underlying FocusTrap instance. */ focusTrap: FocusTrap; @@ -432,15 +432,9 @@ export class CdkTrapFocus implements OnDestroy, AfterContentInit, OnChanges, DoC */ @Input({alias: 'cdkTrapFocusAutoCapture', transform: booleanAttribute}) autoCapture: boolean; - constructor( - private _elementRef: ElementRef, - private _focusTrapFactory: FocusTrapFactory, - /** - * @deprecated No longer being used. To be removed. - * @breaking-change 13.0.0 - */ - @Inject(DOCUMENT) _document: any, - ) { + constructor(...args: unknown[]); + + constructor() { const platform = inject(Platform); if (platform.isBrowser) { diff --git a/src/cdk/a11y/high-contrast-mode/high-contrast-mode-detector.ts b/src/cdk/a11y/high-contrast-mode/high-contrast-mode-detector.ts index 238d0ddbc3ea..67eede2507f4 100644 --- a/src/cdk/a11y/high-contrast-mode/high-contrast-mode-detector.ts +++ b/src/cdk/a11y/high-contrast-mode/high-contrast-mode-detector.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {inject, Inject, Injectable, OnDestroy} from '@angular/core'; +import {inject, Injectable, OnDestroy} from '@angular/core'; import {BreakpointObserver} from '@angular/cdk/layout'; import {Platform} from '@angular/cdk/platform'; import {DOCUMENT} from '@angular/common'; @@ -41,20 +41,19 @@ export const HIGH_CONTRAST_MODE_ACTIVE_CSS_CLASS = 'cdk-high-contrast-active'; */ @Injectable({providedIn: 'root'}) export class HighContrastModeDetector implements OnDestroy { + private _platform = inject(Platform); + /** * Figuring out the high contrast mode and adding the body classes can cause * some expensive layouts. This flag is used to ensure that we only do it once. */ private _hasCheckedHighContrastMode: boolean; - private _document: Document; + private _document = inject(DOCUMENT); private _breakpointSubscription: Subscription; - constructor( - private _platform: Platform, - @Inject(DOCUMENT) document: any, - ) { - this._document = document; + constructor(...args: unknown[]); + constructor() { this._breakpointSubscription = inject(BreakpointObserver) .observe('(forced-colors: active)') .subscribe(() => { diff --git a/src/cdk/a11y/input-modality/input-modality-detector.ts b/src/cdk/a11y/input-modality/input-modality-detector.ts index cb6b35adf494..932fba982dc3 100644 --- a/src/cdk/a11y/input-modality/input-modality-detector.ts +++ b/src/cdk/a11y/input-modality/input-modality-detector.ts @@ -7,7 +7,7 @@ */ import {ALT, CONTROL, MAC_META, META, SHIFT} from '@angular/cdk/keycodes'; -import {Inject, Injectable, InjectionToken, OnDestroy, Optional, NgZone} from '@angular/core'; +import {Injectable, InjectionToken, OnDestroy, NgZone, inject} from '@angular/core'; import {normalizePassiveListenerOptions, Platform, _getEventTarget} from '@angular/cdk/platform'; import {DOCUMENT} from '@angular/common'; import {BehaviorSubject, Observable} from 'rxjs'; @@ -90,6 +90,8 @@ const modalityEventListenerOptions = normalizePassiveListenerOptions({ */ @Injectable({providedIn: 'root'}) export class InputModalityDetector implements OnDestroy { + private readonly _platform = inject(Platform); + /** Emits whenever an input modality is detected. */ readonly modalityDetected: Observable; @@ -172,14 +174,13 @@ export class InputModalityDetector implements OnDestroy { this._mostRecentTarget = _getEventTarget(event); }; - constructor( - private readonly _platform: Platform, - ngZone: NgZone, - @Inject(DOCUMENT) document: Document, - @Optional() - @Inject(INPUT_MODALITY_DETECTOR_OPTIONS) - options?: InputModalityDetectorOptions, - ) { + constructor(...args: unknown[]); + + constructor() { + const ngZone = inject(NgZone); + const document = inject(DOCUMENT); + const options = inject(INPUT_MODALITY_DETECTOR_OPTIONS, {optional: true}); + this._options = { ...INPUT_MODALITY_DETECTOR_DEFAULT_OPTIONS, ...options, @@ -191,7 +192,7 @@ export class InputModalityDetector implements OnDestroy { // If we're not in a browser, this service should do nothing, as there's no relevant input // modality to detect. - if (_platform.isBrowser) { + if (this._platform.isBrowser) { ngZone.runOutsideAngular(() => { document.addEventListener('keydown', this._onKeydown, modalityEventListenerOptions); document.addEventListener('mousedown', this._onMousedown, modalityEventListenerOptions); diff --git a/src/cdk/a11y/interactivity-checker/interactivity-checker.ts b/src/cdk/a11y/interactivity-checker/interactivity-checker.ts index 10cee5be7dee..e77eee7d044c 100644 --- a/src/cdk/a11y/interactivity-checker/interactivity-checker.ts +++ b/src/cdk/a11y/interactivity-checker/interactivity-checker.ts @@ -7,7 +7,7 @@ */ import {Platform} from '@angular/cdk/platform'; -import {Injectable} from '@angular/core'; +import {Injectable, inject} from '@angular/core'; /** * Configuration for the isFocusable method. @@ -29,7 +29,10 @@ export class IsFocusableConfig { */ @Injectable({providedIn: 'root'}) export class InteractivityChecker { - constructor(private _platform: Platform) {} + private _platform = inject(Platform); + + constructor(...args: unknown[]); + constructor() {} /** * Gets whether an element is disabled. diff --git a/src/cdk/a11y/live-announcer/live-announcer.spec.ts b/src/cdk/a11y/live-announcer/live-announcer.spec.ts index b1509f5e7edc..13ad187f006e 100644 --- a/src/cdk/a11y/live-announcer/live-announcer.spec.ts +++ b/src/cdk/a11y/live-announcer/live-announcer.spec.ts @@ -1,8 +1,8 @@ import {MutationObserverFactory} from '@angular/cdk/observers'; import {Overlay} from '@angular/cdk/overlay'; import {ComponentPortal} from '@angular/cdk/portal'; -import {Component} from '@angular/core'; -import {ComponentFixture, TestBed, fakeAsync, flush, inject, tick} from '@angular/core/testing'; +import {Component, inject} from '@angular/core'; +import {ComponentFixture, TestBed, fakeAsync, flush, tick} from '@angular/core/testing'; import {By} from '@angular/platform-browser'; import {A11yModule} from '../index'; import {LiveAnnouncer} from './live-announcer'; @@ -133,12 +133,9 @@ describe('LiveAnnouncer', () => { const extraElement = document.createElement('div'); extraElement.classList.add('cdk-live-announcer-element'); document.body.appendChild(extraElement); - - inject([LiveAnnouncer], (la: LiveAnnouncer) => { - announcer = la; - ariaLiveElement = getLiveElement(); - fixture = TestBed.createComponent(TestApp); - })(); + announcer = TestBed.inject(LiveAnnouncer); + ariaLiveElement = getLiveElement(); + fixture = TestBed.createComponent(TestApp); announcer.announce('Hey Google'); tick(100); @@ -229,10 +226,10 @@ describe('LiveAnnouncer', () => { }); }); - beforeEach(inject([LiveAnnouncer], (la: LiveAnnouncer) => { - announcer = la; + beforeEach(() => { + announcer = TestBed.inject(LiveAnnouncer); ariaLiveElement = getLiveElement(); - })); + }); it('should allow to use a custom live element', fakeAsync(() => { announcer.announce('Custom Element'); @@ -260,10 +257,10 @@ describe('LiveAnnouncer', () => { }); }); - beforeEach(inject([LiveAnnouncer], (la: LiveAnnouncer) => { - announcer = la; + beforeEach(() => { + announcer = TestBed.inject(LiveAnnouncer); ariaLiveElement = getLiveElement(); - })); + }); it('should pick up the default politeness from the injection token', fakeAsync(() => { announcer.announce('Hello'); @@ -313,15 +310,13 @@ describe('CdkAriaLive', () => { }); })); - beforeEach(fakeAsync( - inject([LiveAnnouncer], (la: LiveAnnouncer) => { - announcer = la; - announcerSpy = spyOn(la, 'announce').and.callThrough(); - fixture = TestBed.createComponent(DivWithCdkAriaLive); - fixture.detectChanges(); - flush(); - }), - )); + beforeEach(fakeAsync(() => { + announcer = TestBed.inject(LiveAnnouncer); + announcerSpy = spyOn(announcer, 'announce').and.callThrough(); + fixture = TestBed.createComponent(DivWithCdkAriaLive); + fixture.detectChanges(); + flush(); + })); it('should default politeness to polite', fakeAsync(() => { fixture.componentInstance.content = 'New content'; @@ -401,7 +396,7 @@ function getLiveElement(): Element { imports: [A11yModule], }) class TestApp { - constructor(public live: LiveAnnouncer) {} + live = inject(LiveAnnouncer); announceText(message: string) { this.live.announce(message); diff --git a/src/cdk/a11y/live-announcer/live-announcer.ts b/src/cdk/a11y/live-announcer/live-announcer.ts index b9ec9e6fe652..4a01191651a9 100644 --- a/src/cdk/a11y/live-announcer/live-announcer.ts +++ b/src/cdk/a11y/live-announcer/live-announcer.ts @@ -8,16 +8,7 @@ import {ContentObserver} from '@angular/cdk/observers'; import {DOCUMENT} from '@angular/common'; -import { - Directive, - ElementRef, - Inject, - Injectable, - Input, - NgZone, - OnDestroy, - Optional, -} from '@angular/core'; +import {Directive, ElementRef, Injectable, Input, NgZone, OnDestroy, inject} from '@angular/core'; import {Subscription} from 'rxjs'; import { AriaLivePoliteness, @@ -30,24 +21,21 @@ let uniqueIds = 0; @Injectable({providedIn: 'root'}) export class LiveAnnouncer implements OnDestroy { + private _ngZone = inject(NgZone); + private _defaultOptions = inject(LIVE_ANNOUNCER_DEFAULT_OPTIONS, { + optional: true, + }); + private _liveElement: HTMLElement; - private _document: Document; + private _document = inject(DOCUMENT); private _previousTimeout: number; private _currentPromise: Promise | undefined; private _currentResolve: (() => void) | undefined; - constructor( - @Optional() @Inject(LIVE_ANNOUNCER_ELEMENT_TOKEN) elementToken: any, - private _ngZone: NgZone, - @Inject(DOCUMENT) _document: any, - @Optional() - @Inject(LIVE_ANNOUNCER_DEFAULT_OPTIONS) - private _defaultOptions?: LiveAnnouncerDefaultOptions, - ) { - // We inject the live element and document as `any` because the constructor signature cannot - // reference browser globals (HTMLElement, Document) on non-browser environments, since having - // a class decorator causes TypeScript to preserve the constructor signature types. - this._document = _document; + constructor(...args: unknown[]); + + constructor() { + const elementToken = inject(LIVE_ANNOUNCER_ELEMENT_TOKEN, {optional: true}); this._liveElement = elementToken || this._createLiveElement(); } @@ -225,6 +213,11 @@ export class LiveAnnouncer implements OnDestroy { standalone: true, }) export class CdkAriaLive implements OnDestroy { + private _elementRef = inject(ElementRef); + private _liveAnnouncer = inject(LiveAnnouncer); + private _contentObserver = inject(ContentObserver); + private _ngZone = inject(NgZone); + /** The aria-live politeness level to use when announcing messages. */ @Input('cdkAriaLive') get politeness(): AriaLivePoliteness { @@ -261,12 +254,9 @@ export class CdkAriaLive implements OnDestroy { private _previousAnnouncedText?: string; private _subscription: Subscription | null; - constructor( - private _elementRef: ElementRef, - private _liveAnnouncer: LiveAnnouncer, - private _contentObserver: ContentObserver, - private _ngZone: NgZone, - ) {} + constructor(...args: unknown[]); + + constructor() {} ngOnDestroy() { if (this._subscription) { diff --git a/src/cdk/accordion/accordion-item.ts b/src/cdk/accordion/accordion-item.ts index e2001b1cc665..dfb76a07125e 100644 --- a/src/cdk/accordion/accordion-item.ts +++ b/src/cdk/accordion/accordion-item.ts @@ -12,11 +12,10 @@ import { EventEmitter, Input, OnDestroy, - Optional, ChangeDetectorRef, - SkipSelf, - Inject, booleanAttribute, + inject, + OnInit, } from '@angular/core'; import {UniqueSelectionDispatcher} from '@angular/cdk/collections'; import {CDK_ACCORDION, CdkAccordion} from './accordion'; @@ -39,7 +38,11 @@ let nextId = 0; ], standalone: true, }) -export class CdkAccordionItem implements OnDestroy { +export class CdkAccordionItem implements OnInit, OnDestroy { + accordion = inject(CDK_ACCORDION, {optional: true, skipSelf: true})!; + private _changeDetectorRef = inject(ChangeDetectorRef); + protected _expansionDispatcher = inject(UniqueSelectionDispatcher); + /** Subscription to openAll/closeAll events. */ private _openCloseAllSubscription = Subscription.EMPTY; /** Event emitted every time the AccordionItem is closed. */ @@ -95,12 +98,11 @@ export class CdkAccordionItem implements OnDestroy { /** Unregister function for _expansionDispatcher. */ private _removeUniqueSelectionListener: () => void = () => {}; - constructor( - @Optional() @Inject(CDK_ACCORDION) @SkipSelf() public accordion: CdkAccordion, - private _changeDetectorRef: ChangeDetectorRef, - protected _expansionDispatcher: UniqueSelectionDispatcher, - ) { - this._removeUniqueSelectionListener = _expansionDispatcher.listen( + constructor(...args: unknown[]); + constructor() {} + + ngOnInit() { + this._removeUniqueSelectionListener = this._expansionDispatcher.listen( (id: string, accordionId: string) => { if ( this.accordion && diff --git a/src/cdk/bidi/directionality.spec.ts b/src/cdk/bidi/directionality.spec.ts index 03a64b684547..72166e369169 100644 --- a/src/cdk/bidi/directionality.spec.ts +++ b/src/cdk/bidi/directionality.spec.ts @@ -1,5 +1,5 @@ import {waitForAsync, fakeAsync, TestBed, flush} from '@angular/core/testing'; -import {Component, ViewChild, signal} from '@angular/core'; +import {Component, ViewChild, signal, inject} from '@angular/core'; import {By} from '@angular/platform-browser'; import {BidiModule, Directionality, Dir, Direction, DIR_DOCUMENT} from './index'; @@ -166,7 +166,7 @@ describe('Directionality', () => { imports: [BidiModule], }) class InjectsDirectionality { - constructor(public dir: Directionality) {} + dir = inject(Directionality); } @Component({ diff --git a/src/cdk/bidi/directionality.ts b/src/cdk/bidi/directionality.ts index 3eda68cfc6b1..1bab83bb8d75 100644 --- a/src/cdk/bidi/directionality.ts +++ b/src/cdk/bidi/directionality.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {EventEmitter, Inject, Injectable, Optional, OnDestroy} from '@angular/core'; +import {EventEmitter, Injectable, OnDestroy, inject} from '@angular/core'; import {DIR_DOCUMENT} from './dir-document-token'; export type Direction = 'ltr' | 'rtl'; @@ -38,7 +38,11 @@ export class Directionality implements OnDestroy { /** Stream that emits whenever the 'ltr' / 'rtl' state changes. */ readonly change = new EventEmitter(); - constructor(@Optional() @Inject(DIR_DOCUMENT) _document?: any) { + constructor(...args: unknown[]); + + constructor() { + const _document = inject(DIR_DOCUMENT, {optional: true}); + if (_document) { const bodyDir = _document.body ? _document.body.dir : null; const htmlDir = _document.documentElement ? _document.documentElement.dir : null; diff --git a/src/cdk/clipboard/clipboard.ts b/src/cdk/clipboard/clipboard.ts index f9bd5174abdf..ca840c0c53ba 100644 --- a/src/cdk/clipboard/clipboard.ts +++ b/src/cdk/clipboard/clipboard.ts @@ -7,7 +7,7 @@ */ import {DOCUMENT} from '@angular/common'; -import {Inject, Injectable} from '@angular/core'; +import {Injectable, inject} from '@angular/core'; import {PendingCopy} from './pending-copy'; /** @@ -15,11 +15,10 @@ import {PendingCopy} from './pending-copy'; */ @Injectable({providedIn: 'root'}) export class Clipboard { - private readonly _document: Document; + private readonly _document = inject(DOCUMENT); - constructor(@Inject(DOCUMENT) document: any) { - this._document = document; - } + constructor(...args: unknown[]); + constructor() {} /** * Copies the provided text into the user's clipboard. diff --git a/src/cdk/clipboard/copy-to-clipboard.ts b/src/cdk/clipboard/copy-to-clipboard.ts index 3ee880859519..4a912c6fd434 100644 --- a/src/cdk/clipboard/copy-to-clipboard.ts +++ b/src/cdk/clipboard/copy-to-clipboard.ts @@ -13,9 +13,8 @@ import { Output, NgZone, InjectionToken, - Inject, - Optional, OnDestroy, + inject, } from '@angular/core'; import {Clipboard} from './clipboard'; import {PendingCopy} from './pending-copy'; @@ -43,6 +42,9 @@ export const CDK_COPY_TO_CLIPBOARD_CONFIG = new InjectionToken extends BasePortalOutlet implements OnDestroy { + protected _elementRef = inject(ElementRef); + protected _focusTrapFactory = inject(FocusTrapFactory); + readonly _config: C; + private _interactivityChecker = inject(InteractivityChecker); + protected _ngZone = inject(NgZone); + private _overlayRef = inject(OverlayRef); + private _focusMonitor = inject(FocusMonitor); + private _platform = inject(Platform); - protected _document: Document; + protected _document = inject(DOCUMENT, {optional: true})!; /** The portal outlet inside of this container into which the dialog content will be loaded. */ @ViewChild(CdkPortalOutlet, {static: true}) _portalOutlet: CdkPortalOutlet; @@ -108,19 +114,14 @@ export class CdkDialogContainer private _isDestroyed = false; - constructor( - protected _elementRef: ElementRef, - protected _focusTrapFactory: FocusTrapFactory, - @Optional() @Inject(DOCUMENT) _document: any, - @Inject(DialogConfig) readonly _config: C, - private _interactivityChecker: InteractivityChecker, - protected _ngZone: NgZone, - private _overlayRef: OverlayRef, - private _focusMonitor?: FocusMonitor, - ) { + constructor(...args: unknown[]); + + constructor() { super(); - this._document = _document; + // Callback is primarily for some internal tests + // that were instantiating the dialog container manually. + this._config = (inject(DialogConfig, {optional: true}) || new DialogConfig()) as C; if (this._config.ariaLabelledBy) { this._ariaLabelledByQueue.push(this._config.ariaLabelledBy); diff --git a/src/cdk/dialog/dialog.spec.ts b/src/cdk/dialog/dialog.spec.ts index 72506a79ba86..538ec73fa72b 100644 --- a/src/cdk/dialog/dialog.spec.ts +++ b/src/cdk/dialog/dialog.spec.ts @@ -14,7 +14,6 @@ import { Component, ComponentRef, Directive, - Inject, InjectionToken, Injector, TemplateRef, @@ -1209,7 +1208,7 @@ describe('Dialog with a parent Dialog', () => { standalone: true, }) class DirectiveWithViewContainer { - constructor(public viewContainerRef: ViewContainerRef) {} + viewContainerRef = inject(ViewContainerRef); } @Component({ @@ -1217,7 +1216,7 @@ class DirectiveWithViewContainer { template: 'hello', }) class ComponentWithOnPushViewContainer { - constructor(public viewContainerRef: ViewContainerRef) {} + viewContainerRef = inject(ViewContainerRef); } @Component({ @@ -1260,11 +1259,9 @@ class ComponentWithTemplateRef { imports: [DialogModule], }) class PizzaMsg { - constructor( - public dialogRef: DialogRef, - public dialogInjector: Injector, - public directionality: Directionality, - ) {} + dialogRef = inject>(DialogRef); + dialogInjector = inject(Injector); + directionality = inject(Directionality); } @Component({ @@ -1285,7 +1282,7 @@ class ContentElementDialog { imports: [DialogModule], }) class ComponentThatProvidesMatDialog { - constructor(public dialog: Dialog) {} + dialog = inject(Dialog); } /** Simple component for testing ComponentPortal. */ @@ -1295,7 +1292,7 @@ class ComponentThatProvidesMatDialog { imports: [DialogModule], }) class DialogWithInjectedData { - constructor(@Inject(DIALOG_DATA) public data: any) {} + data = inject(DIALOG_DATA); } @Component({ diff --git a/src/cdk/dialog/dialog.ts b/src/cdk/dialog/dialog.ts index 25c1aa51a825..7b593a0f9f48 100644 --- a/src/cdk/dialog/dialog.ts +++ b/src/cdk/dialog/dialog.ts @@ -13,10 +13,8 @@ import { OnDestroy, Type, StaticProvider, - Inject, - Optional, - SkipSelf, ComponentRef, + inject, } from '@angular/core'; import {BasePortalOutlet, ComponentPortal, TemplatePortal} from '@angular/cdk/portal'; import {of as observableOf, Observable, Subject, defer} from 'rxjs'; @@ -28,7 +26,6 @@ import { Overlay, OverlayRef, OverlayConfig, - ScrollStrategy, OverlayContainer, } from '@angular/cdk/overlay'; import {startWith} from 'rxjs/operators'; @@ -41,11 +38,17 @@ let uniqueId = 0; @Injectable({providedIn: 'root'}) export class Dialog implements OnDestroy { + private _overlay = inject(Overlay); + private _injector = inject(Injector); + private _defaultOptions = inject(DEFAULT_DIALOG_CONFIG, {optional: true}); + private _parentDialog = inject(Dialog, {optional: true, skipSelf: true}); + private _overlayContainer = inject(OverlayContainer); + private _openDialogsAtThisLevel: DialogRef[] = []; private readonly _afterAllClosedAtThisLevel = new Subject(); private readonly _afterOpenedAtThisLevel = new Subject(); private _ariaHiddenElements = new Map(); - private _scrollStrategy: () => ScrollStrategy; + private _scrollStrategy = inject(DIALOG_SCROLL_STRATEGY); /** Keeps track of the currently-open dialogs. */ get openDialogs(): readonly DialogRef[] { @@ -67,16 +70,9 @@ export class Dialog implements OnDestroy { : this._getAfterAllClosed().pipe(startWith(undefined)), ); - constructor( - private _overlay: Overlay, - private _injector: Injector, - @Optional() @Inject(DEFAULT_DIALOG_CONFIG) private _defaultOptions: DialogConfig, - @Optional() @SkipSelf() private _parentDialog: Dialog, - private _overlayContainer: OverlayContainer, - @Inject(DIALOG_SCROLL_STRATEGY) scrollStrategy: any, - ) { - this._scrollStrategy = scrollStrategy; - } + constructor(...args: unknown[]); + + constructor() {} /** * Opens a modal dialog containing the given component. diff --git a/src/cdk/drag-drop/directives/drag-handle.ts b/src/cdk/drag-drop/directives/drag-handle.ts index a871c42d6d63..9d7c0fa8809e 100644 --- a/src/cdk/drag-drop/directives/drag-handle.ts +++ b/src/cdk/drag-drop/directives/drag-handle.ts @@ -9,13 +9,11 @@ import { Directive, ElementRef, - Inject, InjectionToken, Input, OnDestroy, - Optional, - SkipSelf, booleanAttribute, + inject, } from '@angular/core'; import {Subject} from 'rxjs'; import type {CdkDrag} from './drag'; @@ -39,6 +37,10 @@ export const CDK_DRAG_HANDLE = new InjectionToken('CdkDragHandle' providers: [{provide: CDK_DRAG_HANDLE, useExisting: CdkDragHandle}], }) export class CdkDragHandle implements OnDestroy { + element = inject>(ElementRef); + + private _parentDrag = inject(CDK_DRAG_PARENT, {optional: true, skipSelf: true}); + /** Emits when the state of the handle has changed. */ readonly _stateChanges = new Subject(); @@ -53,15 +55,14 @@ export class CdkDragHandle implements OnDestroy { } private _disabled = false; - constructor( - public element: ElementRef, - @Inject(CDK_DRAG_PARENT) @Optional() @SkipSelf() private _parentDrag?: CdkDrag, - ) { + constructor(...args: unknown[]); + + constructor() { if (typeof ngDevMode === 'undefined' || ngDevMode) { - assertElementNode(element.nativeElement, 'cdkDragHandle'); + assertElementNode(this.element.nativeElement, 'cdkDragHandle'); } - _parentDrag?._addHandle(this); + this._parentDrag?._addHandle(this); } ngOnDestroy() { diff --git a/src/cdk/drag-drop/directives/drag-placeholder.ts b/src/cdk/drag-drop/directives/drag-placeholder.ts index 5afbfe04bf8c..c1725bac1307 100644 --- a/src/cdk/drag-drop/directives/drag-placeholder.ts +++ b/src/cdk/drag-drop/directives/drag-placeholder.ts @@ -26,12 +26,16 @@ export const CDK_DRAG_PLACEHOLDER = new InjectionToken('CdkD providers: [{provide: CDK_DRAG_PLACEHOLDER, useExisting: CdkDragPlaceholder}], }) export class CdkDragPlaceholder implements OnDestroy { + templateRef = inject>(TemplateRef); + private _drag = inject(CDK_DRAG_PARENT, {optional: true}); /** Context data to be added to the placeholder template instance. */ @Input() data: T; - constructor(public templateRef: TemplateRef) { + constructor(...args: unknown[]); + + constructor() { this._drag?._setPlaceholderTemplate(this); } diff --git a/src/cdk/drag-drop/directives/drag-preview.ts b/src/cdk/drag-drop/directives/drag-preview.ts index 73a8c17219f5..9f5cb591bd4c 100644 --- a/src/cdk/drag-drop/directives/drag-preview.ts +++ b/src/cdk/drag-drop/directives/drag-preview.ts @@ -34,6 +34,8 @@ export const CDK_DRAG_PREVIEW = new InjectionToken('CdkDragPrevi providers: [{provide: CDK_DRAG_PREVIEW, useExisting: CdkDragPreview}], }) export class CdkDragPreview implements OnDestroy { + templateRef = inject>(TemplateRef); + private _drag = inject(CDK_DRAG_PARENT, {optional: true}); /** Context data to be added to the preview template instance. */ @@ -42,7 +44,9 @@ export class CdkDragPreview implements OnDestroy { /** Whether the preview should preserve the same size as the item that is being dragged. */ @Input({transform: booleanAttribute}) matchSize: boolean = false; - constructor(public templateRef: TemplateRef) { + constructor(...args: unknown[]); + + constructor() { this._drag?._setPreviewTemplate(this); } diff --git a/src/cdk/drag-drop/directives/drag.ts b/src/cdk/drag-drop/directives/drag.ts index f4469556e027..1aa0ea035ba1 100644 --- a/src/cdk/drag-drop/directives/drag.ts +++ b/src/cdk/drag-drop/directives/drag.ts @@ -7,23 +7,18 @@ */ import {Directionality} from '@angular/cdk/bidi'; -import {DOCUMENT} from '@angular/common'; import { Directive, ElementRef, EventEmitter, - Inject, Input, NgZone, OnDestroy, - Optional, Output, - SkipSelf, ViewContainerRef, OnChanges, SimpleChanges, ChangeDetectorRef, - Self, InjectionToken, booleanAttribute, afterNextRender, @@ -76,6 +71,15 @@ export const CDK_DROP_LIST = new InjectionToken('CdkDropList'); providers: [{provide: CDK_DRAG_PARENT, useExisting: CdkDrag}], }) export class CdkDrag implements AfterViewInit, OnChanges, OnDestroy { + element = inject>(ElementRef); + dropContainer = inject(CDK_DROP_LIST, {optional: true, skipSelf: true})!; + private _ngZone = inject(NgZone); + private _viewContainerRef = inject(ViewContainerRef); + private _dir = inject(Directionality, {optional: true}); + private _changeDetectorRef = inject(ChangeDetectorRef); + private _selfHandle = inject(CDK_DRAG_HANDLE, {optional: true, self: true}); + private _parentDrag = inject(CDK_DRAG_PARENT, {optional: true, skipSelf: true}); + private readonly _destroyed = new Subject(); private static _dragInstances: CdkDrag[] = []; private _handles = new BehaviorSubject([]); @@ -121,7 +125,7 @@ export class CdkDrag implements AfterViewInit, OnChanges, OnDestroy { /** Whether starting to drag this element is disabled. */ @Input({alias: 'cdkDragDisabled', transform: booleanAttribute}) get disabled(): boolean { - return this._disabled || (this.dropContainer && this.dropContainer.disabled); + return this._disabled || !!(this.dropContainer && this.dropContainer.disabled); } set disabled(value: boolean) { this._disabled = value; @@ -220,26 +224,14 @@ export class CdkDrag implements AfterViewInit, OnChanges, OnDestroy { private _injector = inject(Injector); - constructor( - /** Element that the draggable is attached to. */ - public element: ElementRef, - /** Droppable container that the draggable is a part of. */ - @Inject(CDK_DROP_LIST) @Optional() @SkipSelf() public dropContainer: CdkDropList, - /** - * @deprecated `_document` parameter no longer being used and will be removed. - * @breaking-change 12.0.0 - */ - @Inject(DOCUMENT) _document: any, - private _ngZone: NgZone, - private _viewContainerRef: ViewContainerRef, - @Optional() @Inject(CDK_DRAG_CONFIG) config: DragDropConfig, - @Optional() private _dir: Directionality, - dragDrop: DragDrop, - private _changeDetectorRef: ChangeDetectorRef, - @Optional() @Self() @Inject(CDK_DRAG_HANDLE) private _selfHandle?: CdkDragHandle, - @Optional() @SkipSelf() @Inject(CDK_DRAG_PARENT) private _parentDrag?: CdkDrag, - ) { - this._dragRef = dragDrop.createDrag(element, { + constructor(...args: unknown[]); + + constructor() { + const dropContainer = this.dropContainer; + const config = inject(CDK_DRAG_CONFIG, {optional: true}); + const dragDrop = inject(DragDrop); + + this._dragRef = dragDrop.createDrag(this.element, { dragStartThreshold: config && config.dragStartThreshold != null ? config.dragStartThreshold : 5, pointerDirectionChangeThreshold: diff --git a/src/cdk/drag-drop/directives/drop-list-shared.spec.ts b/src/cdk/drag-drop/directives/drop-list-shared.spec.ts index 676a7c19e318..139ec0f00efb 100644 --- a/src/cdk/drag-drop/directives/drop-list-shared.spec.ts +++ b/src/cdk/drag-drop/directives/drop-list-shared.spec.ts @@ -4890,6 +4890,8 @@ export function getHorizontalFixtures(listOrientation: Exclude; @ViewChild(CdkDropList) dropInstance: CdkDropList; items = [ @@ -4903,7 +4905,9 @@ export function getHorizontalFixtures(listOrientation: Exclude; @ViewChild(CdkDropList) dropInstance: CdkDropList; @ViewChild('alternatePreviewContainer') alternatePreviewContainer: ElementRef; @@ -5041,8 +5047,6 @@ export class DraggableInDropZone implements AfterViewInit { dropLockAxis = signal(undefined); scale = 1; - constructor(protected _elementRef: ElementRef) {} - ngAfterViewInit() { // Firefox preserves the `scrollTop` value from previous similar containers. This // could throw off test assertions and result in flaky results. @@ -5088,8 +5092,8 @@ class ConnectedDropListsInOnPush {} imports: [CdkDropList, CdkDrag, NgFor], }) export class DraggableInScrollableVerticalDropZone extends DraggableInDropZone { - constructor(elementRef: ElementRef) { - super(elementRef); + constructor() { + super(); for (let i = 0; i < 60; i++) { this.items.push({value: `Extra item ${i}`, height: ITEM_HEIGHT, margin: 0}); @@ -5119,8 +5123,8 @@ export class DraggableInScrollableVerticalDropZone extends DraggableInDropZone { class DraggableInScrollableParentContainer extends DraggableInDropZone implements AfterViewInit { @ViewChild('scrollContainer') scrollContainer: ElementRef; - constructor(elementRef: ElementRef) { - super(elementRef); + constructor() { + super(); for (let i = 0; i < 60; i++) { this.items.push({value: `Extra item ${i}`, height: ITEM_HEIGHT, margin: 0}); @@ -5660,10 +5664,6 @@ class ConnectedWrappedDropZones { imports: [CdkDropList, CdkDrag], }) class DraggableWithCanvasInDropZone extends DraggableInDropZone implements AfterViewInit { - constructor(elementRef: ElementRef) { - super(elementRef); - } - override ngAfterViewInit() { super.ngAfterViewInit(); const canvases = this._elementRef.nativeElement.querySelectorAll('canvas'); diff --git a/src/cdk/drag-drop/directives/drop-list.ts b/src/cdk/drag-drop/directives/drop-list.ts index db13704b368b..5f5a8056f52a 100644 --- a/src/cdk/drag-drop/directives/drop-list.ts +++ b/src/cdk/drag-drop/directives/drop-list.ts @@ -13,12 +13,10 @@ import { Input, OnDestroy, Output, - Optional, Directive, ChangeDetectorRef, - SkipSelf, - Inject, booleanAttribute, + inject, } from '@angular/core'; import {Directionality} from '@angular/cdk/bidi'; import {ScrollDispatcher} from '@angular/cdk/scrolling'; @@ -55,6 +53,15 @@ let _uniqueIdCounter = 0; }, }) export class CdkDropList implements OnDestroy { + element = inject>(ElementRef); + private _changeDetectorRef = inject(ChangeDetectorRef); + private _scrollDispatcher = inject(ScrollDispatcher); + private _dir = inject(Directionality, {optional: true}); + private _group = inject>(CDK_DROP_LIST_GROUP, { + optional: true, + skipSelf: true, + }); + /** Emits when the list has been destroyed. */ private readonly _destroyed = new Subject(); @@ -173,24 +180,17 @@ export class CdkDropList implements OnDestroy { */ private _unsortedItems = new Set(); - constructor( - /** Element that the drop list is attached to. */ - public element: ElementRef, - dragDrop: DragDrop, - private _changeDetectorRef: ChangeDetectorRef, - private _scrollDispatcher: ScrollDispatcher, - @Optional() private _dir?: Directionality, - @Optional() - @Inject(CDK_DROP_LIST_GROUP) - @SkipSelf() - private _group?: CdkDropListGroup, - @Optional() @Inject(CDK_DRAG_CONFIG) config?: DragDropConfig, - ) { + constructor(...args: unknown[]); + + constructor() { + const dragDrop = inject(DragDrop); + const config = inject(CDK_DRAG_CONFIG, {optional: true}); + if (typeof ngDevMode === 'undefined' || ngDevMode) { - assertElementNode(element.nativeElement, 'cdkDropList'); + assertElementNode(this.element.nativeElement, 'cdkDropList'); } - this._dropListRef = dragDrop.createDropList(element); + this._dropListRef = dragDrop.createDropList(this.element); this._dropListRef.data = this; if (config) { @@ -213,8 +213,8 @@ export class CdkDropList implements OnDestroy { this._handleEvents(this._dropListRef); CdkDropList._dropLists.push(this); - if (_group) { - _group._items.add(this); + if (this._group) { + this._group._items.add(this); } } diff --git a/src/cdk/drag-drop/drag-drop-registry.ts b/src/cdk/drag-drop/drag-drop-registry.ts index 4bd8ff7dcb92..c63f2982d744 100644 --- a/src/cdk/drag-drop/drag-drop-registry.ts +++ b/src/cdk/drag-drop/drag-drop-registry.ts @@ -9,7 +9,6 @@ import { ChangeDetectionStrategy, Component, - Inject, Injectable, NgZone, OnDestroy, @@ -53,7 +52,8 @@ export class _ResetsLoader {} */ @Injectable({providedIn: 'root'}) export class DragDropRegistry<_ = unknown, __ = unknown> implements OnDestroy { - private _document: Document; + private _ngZone = inject(NgZone); + private _document = inject(DOCUMENT); private _styleLoader = inject(_CdkPrivateStyleLoader); /** Registered drop container instances. */ @@ -99,12 +99,8 @@ export class DragDropRegistry<_ = unknown, __ = unknown> implements OnDestroy { */ readonly scroll: Subject = new Subject(); - constructor( - private _ngZone: NgZone, - @Inject(DOCUMENT) _document: any, - ) { - this._document = _document; - } + constructor(...args: unknown[]); + constructor() {} /** Adds a drop container to the registry. */ registerDropContainer(drop: DropListRef) { diff --git a/src/cdk/drag-drop/drag-drop.spec.ts b/src/cdk/drag-drop/drag-drop.spec.ts index 5919e929144b..7cd74cd9c435 100644 --- a/src/cdk/drag-drop/drag-drop.spec.ts +++ b/src/cdk/drag-drop/drag-drop.spec.ts @@ -1,4 +1,4 @@ -import {Component, ElementRef} from '@angular/core'; +import {Component, ElementRef, inject} from '@angular/core'; import {TestBed, fakeAsync} from '@angular/core/testing'; import {DragDrop} from './drag-drop'; import {DragDropModule} from './drag-drop-module'; @@ -38,5 +38,5 @@ describe('DragDrop', () => { standalone: true, }) class TestComponent { - constructor(public elementRef: ElementRef) {} + elementRef = inject>(ElementRef); } diff --git a/src/cdk/drag-drop/drag-drop.ts b/src/cdk/drag-drop/drag-drop.ts index 9492bc01c0de..eacc8f1bfd8e 100644 --- a/src/cdk/drag-drop/drag-drop.ts +++ b/src/cdk/drag-drop/drag-drop.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Injectable, Inject, NgZone, ElementRef} from '@angular/core'; +import {Injectable, NgZone, ElementRef, inject} from '@angular/core'; import {DOCUMENT} from '@angular/common'; import {ViewportRuler} from '@angular/cdk/scrolling'; import {DragRef, DragRefConfig} from './drag-ref'; @@ -24,12 +24,13 @@ const DEFAULT_CONFIG = { */ @Injectable({providedIn: 'root'}) export class DragDrop { - constructor( - @Inject(DOCUMENT) private _document: any, - private _ngZone: NgZone, - private _viewportRuler: ViewportRuler, - private _dragDropRegistry: DragDropRegistry, - ) {} + private _document = inject(DOCUMENT); + private _ngZone = inject(NgZone); + private _viewportRuler = inject(ViewportRuler); + private _dragDropRegistry = inject(DragDropRegistry); + + constructor(...args: unknown[]); + constructor() {} /** * Turns an element into a draggable item. diff --git a/src/cdk/layout/breakpoints-observer.ts b/src/cdk/layout/breakpoints-observer.ts index 3cfb18f5e6f9..66b3ccc7d384 100644 --- a/src/cdk/layout/breakpoints-observer.ts +++ b/src/cdk/layout/breakpoints-observer.ts @@ -7,7 +7,7 @@ */ import {coerceArray} from '@angular/cdk/coercion'; -import {Injectable, NgZone, OnDestroy} from '@angular/core'; +import {Injectable, NgZone, OnDestroy, inject} from '@angular/core'; import {combineLatest, concat, Observable, Observer, Subject} from 'rxjs'; import {debounceTime, map, skip, startWith, take, takeUntil} from 'rxjs/operators'; import {MediaMatcher} from './media-matcher'; @@ -38,18 +38,19 @@ interface Query { mql: MediaQueryList; } -/** Utility for checking the matching state of @media queries. */ +/** Utility for checking the matching state of `@media` queries. */ @Injectable({providedIn: 'root'}) export class BreakpointObserver implements OnDestroy { + private _mediaMatcher = inject(MediaMatcher); + private _zone = inject(NgZone); + /** A map of all media queries currently being listened for. */ private _queries = new Map(); /** A subject for all other observables to takeUntil based on. */ private readonly _destroySubject = new Subject(); - constructor( - private _mediaMatcher: MediaMatcher, - private _zone: NgZone, - ) {} + constructor(...args: unknown[]); + constructor() {} /** Completes the active subject, signalling to all other observables to complete. */ ngOnDestroy() { diff --git a/src/cdk/layout/media-matcher.ts b/src/cdk/layout/media-matcher.ts index f6912ec19233..4d2164b3ff53 100644 --- a/src/cdk/layout/media-matcher.ts +++ b/src/cdk/layout/media-matcher.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {Injectable, CSP_NONCE, Optional, Inject} from '@angular/core'; +import {Injectable, CSP_NONCE, inject} from '@angular/core'; import {Platform} from '@angular/cdk/platform'; /** Global registry for all dynamically-created, injected media queries. */ @@ -17,13 +17,15 @@ let mediaQueryStyleNode: HTMLStyleElement | undefined; /** A utility for calling matchMedia queries. */ @Injectable({providedIn: 'root'}) export class MediaMatcher { + private _platform = inject(Platform); + private _nonce = inject(CSP_NONCE, {optional: true}); + /** The internal matchMedia method to return back a MediaQueryList like object. */ private _matchMedia: (query: string) => MediaQueryList; - constructor( - private _platform: Platform, - @Optional() @Inject(CSP_NONCE) private _nonce?: string | null, - ) { + constructor(...args: unknown[]); + + constructor() { this._matchMedia = this._platform.isBrowser && window.matchMedia ? // matchMedia is bound to the window scope intentionally as it is an illegal invocation to diff --git a/src/cdk/menu/pointer-focus-tracker.spec.ts b/src/cdk/menu/pointer-focus-tracker.spec.ts index 607d5473f351..8aac6c578a18 100644 --- a/src/cdk/menu/pointer-focus-tracker.spec.ts +++ b/src/cdk/menu/pointer-focus-tracker.spec.ts @@ -1,4 +1,4 @@ -import {Component, QueryList, ElementRef, ViewChildren, AfterViewInit} from '@angular/core'; +import {Component, QueryList, ElementRef, ViewChildren, AfterViewInit, inject} from '@angular/core'; import {waitForAsync, ComponentFixture, TestBed} from '@angular/core/testing'; import {createMouseEvent, dispatchEvent} from '../../cdk/testing/private'; import {Observable} from 'rxjs'; @@ -102,7 +102,7 @@ describe('FocusMouseManger', () => { standalone: true, }) class MockWrapper implements FocusableElement { - constructor(readonly _elementRef: ElementRef) {} + readonly _elementRef = inject>(ElementRef); } @Component({ diff --git a/src/cdk/observers/observe-content.ts b/src/cdk/observers/observe-content.ts index 98d654afaa61..68ecab28c524 100644 --- a/src/cdk/observers/observe-content.ts +++ b/src/cdk/observers/observe-content.ts @@ -65,6 +65,8 @@ export class MutationObserverFactory { /** An injectable service that allows watching elements for changes to their content. */ @Injectable({providedIn: 'root'}) export class ContentObserver implements OnDestroy { + private _mutationObserverFactory = inject(MutationObserverFactory); + /** Keeps track of the existing MutationObservers so they can be reused. */ private _observedElements = new Map< Element, @@ -77,7 +79,8 @@ export class ContentObserver implements OnDestroy { private _ngZone = inject(NgZone); - constructor(private _mutationObserverFactory: MutationObserverFactory) {} + constructor(...args: unknown[]); + constructor() {} ngOnDestroy() { this._observedElements.forEach((_, element) => this._cleanupObserver(element)); @@ -178,6 +181,9 @@ export class ContentObserver implements OnDestroy { standalone: true, }) export class CdkObserveContent implements AfterContentInit, OnDestroy { + private _contentObserver = inject(ContentObserver); + private _elementRef = inject>(ElementRef); + /** Event emitted for each change in the element's content. */ @Output('cdkObserveContent') readonly event = new EventEmitter(); @@ -208,10 +214,8 @@ export class CdkObserveContent implements AfterContentInit, OnDestroy { private _currentSubscription: Subscription | null = null; - constructor( - private _contentObserver: ContentObserver, - private _elementRef: ElementRef, - ) {} + constructor(...args: unknown[]); + constructor() {} ngAfterContentInit() { if (!this._currentSubscription && !this.disabled) { diff --git a/src/cdk/overlay/dispatchers/base-overlay-dispatcher.ts b/src/cdk/overlay/dispatchers/base-overlay-dispatcher.ts index 3e513177043b..edfd897bd90b 100644 --- a/src/cdk/overlay/dispatchers/base-overlay-dispatcher.ts +++ b/src/cdk/overlay/dispatchers/base-overlay-dispatcher.ts @@ -7,7 +7,7 @@ */ import {DOCUMENT} from '@angular/common'; -import {Inject, Injectable, OnDestroy} from '@angular/core'; +import {Injectable, OnDestroy, inject} from '@angular/core'; import type {OverlayRef} from '../overlay-ref'; /** @@ -20,12 +20,12 @@ export abstract class BaseOverlayDispatcher implements OnDestroy { /** Currently attached overlays in the order they were attached. */ _attachedOverlays: OverlayRef[] = []; - protected _document: Document; + protected _document = inject(DOCUMENT); protected _isAttached: boolean; - constructor(@Inject(DOCUMENT) document: any) { - this._document = document; - } + constructor(...args: unknown[]); + + constructor() {} ngOnDestroy(): void { this.detach(); diff --git a/src/cdk/overlay/dispatchers/overlay-keyboard-dispatcher.ts b/src/cdk/overlay/dispatchers/overlay-keyboard-dispatcher.ts index 5fd90dbe58c8..716e6d8ea17f 100644 --- a/src/cdk/overlay/dispatchers/overlay-keyboard-dispatcher.ts +++ b/src/cdk/overlay/dispatchers/overlay-keyboard-dispatcher.ts @@ -6,8 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {DOCUMENT} from '@angular/common'; -import {Inject, Injectable, NgZone, Optional} from '@angular/core'; +import {Injectable, NgZone, inject} from '@angular/core'; import {BaseOverlayDispatcher} from './base-overlay-dispatcher'; import type {OverlayRef} from '../overlay-ref'; @@ -18,13 +17,7 @@ import type {OverlayRef} from '../overlay-ref'; */ @Injectable({providedIn: 'root'}) export class OverlayKeyboardDispatcher extends BaseOverlayDispatcher { - constructor( - @Inject(DOCUMENT) document: any, - /** @breaking-change 14.0.0 _ngZone will be required. */ - @Optional() private _ngZone?: NgZone, - ) { - super(document); - } + private _ngZone = inject(NgZone, {optional: true}); /** Add a new overlay to the list of attached overlay refs. */ override add(overlayRef: OverlayRef): void { diff --git a/src/cdk/overlay/dispatchers/overlay-outside-click-dispatcher.ts b/src/cdk/overlay/dispatchers/overlay-outside-click-dispatcher.ts index 7af50d01b98e..44a5132d45b1 100644 --- a/src/cdk/overlay/dispatchers/overlay-outside-click-dispatcher.ts +++ b/src/cdk/overlay/dispatchers/overlay-outside-click-dispatcher.ts @@ -6,8 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {DOCUMENT} from '@angular/common'; -import {Inject, Injectable, NgZone, Optional} from '@angular/core'; +import {Injectable, NgZone, inject} from '@angular/core'; import {Platform, _getEventTarget} from '@angular/cdk/platform'; import {BaseOverlayDispatcher} from './base-overlay-dispatcher'; import type {OverlayRef} from '../overlay-ref'; @@ -19,19 +18,13 @@ import type {OverlayRef} from '../overlay-ref'; */ @Injectable({providedIn: 'root'}) export class OverlayOutsideClickDispatcher extends BaseOverlayDispatcher { + private _platform = inject(Platform); + private _ngZone = inject(NgZone, {optional: true}); + private _cursorOriginalValue: string; private _cursorStyleIsSet = false; private _pointerDownEventTarget: HTMLElement | null; - constructor( - @Inject(DOCUMENT) document: any, - private _platform: Platform, - /** @breaking-change 14.0.0 _ngZone will be required. */ - @Optional() private _ngZone?: NgZone, - ) { - super(document); - } - /** Add a new overlay to the list of attached overlay refs. */ override add(overlayRef: OverlayRef): void { super.add(overlayRef); diff --git a/src/cdk/overlay/fullscreen-overlay-container.spec.ts b/src/cdk/overlay/fullscreen-overlay-container.spec.ts index 63b704193ae5..38680cefbe6f 100644 --- a/src/cdk/overlay/fullscreen-overlay-container.spec.ts +++ b/src/cdk/overlay/fullscreen-overlay-container.spec.ts @@ -1,6 +1,6 @@ import {DOCUMENT} from '@angular/common'; import {waitForAsync, inject, TestBed} from '@angular/core/testing'; -import {Component, NgModule, ViewChild, ViewContainerRef} from '@angular/core'; +import {Component, NgModule, ViewChild, ViewContainerRef, inject as inject_1} from '@angular/core'; import {PortalModule, CdkPortal} from '@angular/cdk/portal'; import {Overlay, OverlayContainer, OverlayModule, FullscreenOverlayContainer} from './index'; import {TemplatePortalDirective} from '../portal/portal-directives'; @@ -117,9 +117,9 @@ describe('FullscreenOverlayContainer', () => { imports: [TemplatePortalDirective], }) class TestComponentWithTemplatePortals { - @ViewChild(CdkPortal) templatePortal: CdkPortal; + viewContainerRef = inject_1(ViewContainerRef); - constructor(public viewContainerRef: ViewContainerRef) {} + @ViewChild(CdkPortal) templatePortal: CdkPortal; } @NgModule({ diff --git a/src/cdk/overlay/fullscreen-overlay-container.ts b/src/cdk/overlay/fullscreen-overlay-container.ts index 00a2808efc54..6cba048d8f9a 100644 --- a/src/cdk/overlay/fullscreen-overlay-container.ts +++ b/src/cdk/overlay/fullscreen-overlay-container.ts @@ -6,10 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ -import {Injectable, Inject, OnDestroy} from '@angular/core'; +import {Injectable, OnDestroy} from '@angular/core'; import {OverlayContainer} from './overlay-container'; -import {DOCUMENT} from '@angular/common'; -import {Platform} from '@angular/cdk/platform'; /** * Alternative to OverlayContainer that supports correct displaying of overlay elements in @@ -23,8 +21,10 @@ export class FullscreenOverlayContainer extends OverlayContainer implements OnDe private _fullScreenEventName: string | undefined; private _fullScreenListener: () => void; - constructor(@Inject(DOCUMENT) _document: any, platform: Platform) { - super(_document, platform); + constructor(...args: unknown[]); + + constructor() { + super(); } override ngOnDestroy() { diff --git a/src/cdk/overlay/overlay-container.spec.ts b/src/cdk/overlay/overlay-container.spec.ts index 61b01dcc8958..47b586c6c2cd 100644 --- a/src/cdk/overlay/overlay-container.spec.ts +++ b/src/cdk/overlay/overlay-container.spec.ts @@ -1,5 +1,5 @@ -import {waitForAsync, inject, TestBed} from '@angular/core/testing'; -import {Component, NgModule, ViewChild, ViewContainerRef} from '@angular/core'; +import {waitForAsync, TestBed} from '@angular/core/testing'; +import {Component, NgModule, ViewChild, ViewContainerRef, inject} from '@angular/core'; import {PortalModule, CdkPortal} from '@angular/cdk/portal'; import {Overlay, OverlayContainer, OverlayModule} from './index'; @@ -11,11 +11,9 @@ describe('OverlayContainer', () => { TestBed.configureTestingModule({ imports: [OverlayTestModule], }); - })); - beforeEach(inject([Overlay, OverlayContainer], (o: Overlay, oc: OverlayContainer) => { - overlay = o; - overlayContainer = oc; + overlay = TestBed.inject(Overlay); + overlayContainer = TestBed.inject(OverlayContainer); })); it('should remove the overlay container element from the DOM on destruction', () => { @@ -95,9 +93,9 @@ describe('OverlayContainer', () => { imports: [CdkPortal], }) class TestComponentWithTemplatePortals { - @ViewChild(CdkPortal) templatePortal: CdkPortal; + viewContainerRef = inject(ViewContainerRef); - constructor(public viewContainerRef: ViewContainerRef) {} + @ViewChild(CdkPortal) templatePortal: CdkPortal; } @NgModule({ diff --git a/src/cdk/overlay/overlay-container.ts b/src/cdk/overlay/overlay-container.ts index 5c27341638fb..a6b8124dae25 100644 --- a/src/cdk/overlay/overlay-container.ts +++ b/src/cdk/overlay/overlay-container.ts @@ -8,7 +8,6 @@ import {DOCUMENT} from '@angular/common'; import { - Inject, Injectable, OnDestroy, Component, @@ -32,16 +31,14 @@ export class _CdkOverlayStyleLoader {} /** Container inside which all overlays will render. */ @Injectable({providedIn: 'root'}) export class OverlayContainer implements OnDestroy { + protected _platform = inject(Platform); + protected _containerElement: HTMLElement; - protected _document: Document; + protected _document = inject(DOCUMENT); protected _styleLoader = inject(_CdkPrivateStyleLoader); - constructor( - @Inject(DOCUMENT) document: any, - protected _platform: Platform, - ) { - this._document = document; - } + constructor(...args: unknown[]); + constructor() {} ngOnDestroy() { this._containerElement?.remove(); diff --git a/src/cdk/overlay/overlay-directives.ts b/src/cdk/overlay/overlay-directives.ts index 87315cbf6c03..34490e7632a6 100644 --- a/src/cdk/overlay/overlay-directives.ts +++ b/src/cdk/overlay/overlay-directives.ts @@ -13,13 +13,11 @@ import { Directive, ElementRef, EventEmitter, - Inject, InjectionToken, Input, NgZone, OnChanges, OnDestroy, - Optional, Output, SimpleChanges, TemplateRef, @@ -91,10 +89,10 @@ export const CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY = new InjectionToken<() => Sc standalone: true, }) export class CdkOverlayOrigin { - constructor( - /** Reference to the element on which the directive is applied. */ - public elementRef: ElementRef, - ) {} + elementRef = inject(ElementRef); + + constructor(...args: unknown[]); + constructor() {} } /** @@ -107,6 +105,9 @@ export class CdkOverlayOrigin { standalone: true, }) export class CdkConnectedOverlay implements OnDestroy, OnChanges { + private _overlay = inject(Overlay); + private _dir = inject(Directionality, {optional: true}); + private _overlayRef: OverlayRef; private _templatePortal: TemplatePortal; private _backdropSubscription = Subscription.EMPTY; @@ -116,7 +117,7 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges { private _offsetX: number; private _offsetY: number; private _position: FlexibleConnectedPositionStrategy; - private _scrollStrategyFactory: () => ScrollStrategy; + private _scrollStrategyFactory = inject(CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY); private _disposeOnNavigation = false; private _ngZone = inject(NgZone); @@ -238,17 +239,15 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges { /** Emits when there are mouse outside click events that are targeted at the overlay. */ @Output() readonly overlayOutsideClick = new EventEmitter(); + constructor(...args: unknown[]); + // TODO(jelbourn): inputs for size, scroll behavior, animation, etc. - constructor( - private _overlay: Overlay, - templateRef: TemplateRef, - viewContainerRef: ViewContainerRef, - @Inject(CDK_CONNECTED_OVERLAY_SCROLL_STRATEGY) scrollStrategyFactory: any, - @Optional() private _dir: Directionality, - ) { + constructor() { + const templateRef = inject>(TemplateRef); + const viewContainerRef = inject(ViewContainerRef); + this._templatePortal = new TemplatePortal(templateRef, viewContainerRef); - this._scrollStrategyFactory = scrollStrategyFactory; this.scrollStrategy = this._scrollStrategyFactory(); } @@ -326,7 +325,7 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges { const positionStrategy = (this._position = this.positionStrategy || this._createPositionStrategy()); const overlayConfig = new OverlayConfig({ - direction: this._dir, + direction: this._dir || 'ltr', positionStrategy, scrollStrategy: this.scrollStrategy, hasBackdrop: this.hasBackdrop, diff --git a/src/cdk/overlay/overlay.spec.ts b/src/cdk/overlay/overlay.spec.ts index 8acf58d68314..94ed51dea804 100644 --- a/src/cdk/overlay/overlay.spec.ts +++ b/src/cdk/overlay/overlay.spec.ts @@ -10,6 +10,7 @@ import { Type, ViewChild, ViewContainerRef, + inject, } from '@angular/core'; import { ComponentFixture, @@ -352,9 +353,7 @@ describe('Overlay', () => { /** Dummy provider that depends on `Overlay`. */ @Injectable() class CustomErrorHandler extends ErrorHandler { - constructor(private _overlay: Overlay) { - super(); - } + private _overlay = inject(Overlay); override handleError(error: any) { const overlayRef = this._overlay.create({hasBackdrop: !!error}); @@ -1113,9 +1112,9 @@ class PizzaMsg {} imports: [CdkPortal], }) class TestComponentWithTemplatePortals { - @ViewChild(CdkPortal) templatePortal: CdkPortal; + viewContainerRef = inject(ViewContainerRef); - constructor(public viewContainerRef: ViewContainerRef) {} + @ViewChild(CdkPortal) templatePortal: CdkPortal; } class FakePositionStrategy implements PositionStrategy { diff --git a/src/cdk/overlay/overlay.ts b/src/cdk/overlay/overlay.ts index 687b5b358f76..f4565f49cd81 100644 --- a/src/cdk/overlay/overlay.ts +++ b/src/cdk/overlay/overlay.ts @@ -12,12 +12,10 @@ import {DOCUMENT, Location} from '@angular/common'; import { ApplicationRef, ComponentFactoryResolver, - Inject, Injectable, Injector, NgZone, ANIMATION_MODULE_TYPE, - Optional, EnvironmentInjector, inject, } from '@angular/core'; @@ -46,24 +44,24 @@ let nextUniqueId = 0; */ @Injectable({providedIn: 'root'}) export class Overlay { + scrollStrategies = inject(ScrollStrategyOptions); + private _overlayContainer = inject(OverlayContainer); + private _componentFactoryResolver = inject(ComponentFactoryResolver); + private _positionBuilder = inject(OverlayPositionBuilder); + private _keyboardDispatcher = inject(OverlayKeyboardDispatcher); + private _injector = inject(Injector); + private _ngZone = inject(NgZone); + private _document = inject(DOCUMENT); + private _directionality = inject(Directionality); + private _location = inject(Location); + private _outsideClickDispatcher = inject(OverlayOutsideClickDispatcher); + private _animationsModuleType = inject(ANIMATION_MODULE_TYPE, {optional: true}); + private _appRef: ApplicationRef; private _styleLoader = inject(_CdkPrivateStyleLoader); - constructor( - /** Scrolling strategies that can be used when creating an overlay. */ - public scrollStrategies: ScrollStrategyOptions, - private _overlayContainer: OverlayContainer, - private _componentFactoryResolver: ComponentFactoryResolver, - private _positionBuilder: OverlayPositionBuilder, - private _keyboardDispatcher: OverlayKeyboardDispatcher, - private _injector: Injector, - private _ngZone: NgZone, - @Inject(DOCUMENT) private _document: any, - private _directionality: Directionality, - private _location: Location, - private _outsideClickDispatcher: OverlayOutsideClickDispatcher, - @Inject(ANIMATION_MODULE_TYPE) @Optional() private _animationsModuleType?: string, - ) {} + constructor(...args: unknown[]); + constructor() {} /** * Creates an overlay. diff --git a/src/cdk/overlay/position/flexible-connected-position-strategy.spec.ts b/src/cdk/overlay/position/flexible-connected-position-strategy.spec.ts index 32fdf92ccc44..61bc0a212cad 100644 --- a/src/cdk/overlay/position/flexible-connected-position-strategy.spec.ts +++ b/src/cdk/overlay/position/flexible-connected-position-strategy.spec.ts @@ -1,7 +1,13 @@ import {ComponentPortal, PortalModule} from '@angular/cdk/portal'; import {CdkScrollable, ScrollingModule, ViewportRuler} from '@angular/cdk/scrolling'; import {dispatchFakeEvent} from '../../testing/private'; -import {ApplicationRef, Component, ElementRef} from '@angular/core'; +import { + ApplicationRef, + Component, + ElementRef, + Injector, + runInInjectionContext, +} from '@angular/core'; import {fakeAsync, TestBed, tick} from '@angular/core/testing'; import {Subscription} from 'rxjs'; import {map} from 'rxjs/operators'; @@ -2488,9 +2494,19 @@ describe('FlexibleConnectedPositionStrategy', () => { }, ]); - strategy.withScrollableContainers([ - new CdkScrollable(new ElementRef(scrollable), null!, null!), - ]); + const injector = Injector.create({ + parent: TestBed.inject(Injector), + providers: [ + { + provide: ElementRef, + useValue: new ElementRef(scrollable), + }, + ], + }); + + runInInjectionContext(injector, () => { + strategy.withScrollableContainers([new CdkScrollable()]); + }); positionChangeHandler = jasmine.createSpy('positionChange handler'); onPositionChangeSubscription = strategy.positionChanges diff --git a/src/cdk/overlay/position/overlay-position-builder.ts b/src/cdk/overlay/position/overlay-position-builder.ts index 8a20216c746f..ea35f93cfe7c 100644 --- a/src/cdk/overlay/position/overlay-position-builder.ts +++ b/src/cdk/overlay/position/overlay-position-builder.ts @@ -9,7 +9,7 @@ import {Platform} from '@angular/cdk/platform'; import {ViewportRuler} from '@angular/cdk/scrolling'; import {DOCUMENT} from '@angular/common'; -import {Inject, Injectable} from '@angular/core'; +import {Injectable, inject} from '@angular/core'; import {OverlayContainer} from '../overlay-container'; import { FlexibleConnectedPositionStrategy, @@ -20,12 +20,13 @@ import {GlobalPositionStrategy} from './global-position-strategy'; /** Builder for overlay position strategy. */ @Injectable({providedIn: 'root'}) export class OverlayPositionBuilder { - constructor( - private _viewportRuler: ViewportRuler, - @Inject(DOCUMENT) private _document: any, - private _platform: Platform, - private _overlayContainer: OverlayContainer, - ) {} + private _viewportRuler = inject(ViewportRuler); + private _document = inject(DOCUMENT); + private _platform = inject(Platform); + private _overlayContainer = inject(OverlayContainer); + + constructor(...args: unknown[]); + constructor() {} /** * Creates a global position strategy. diff --git a/src/cdk/overlay/scroll/scroll-strategy-options.ts b/src/cdk/overlay/scroll/scroll-strategy-options.ts index 8f88ac342778..6ec0e38c2173 100644 --- a/src/cdk/overlay/scroll/scroll-strategy-options.ts +++ b/src/cdk/overlay/scroll/scroll-strategy-options.ts @@ -8,7 +8,7 @@ import {ScrollDispatcher, ViewportRuler} from '@angular/cdk/scrolling'; import {DOCUMENT} from '@angular/common'; -import {Inject, Injectable, NgZone} from '@angular/core'; +import {Injectable, NgZone, inject} from '@angular/core'; import {BlockScrollStrategy} from './block-scroll-strategy'; import {CloseScrollStrategy, CloseScrollStrategyConfig} from './close-scroll-strategy'; import {NoopScrollStrategy} from './noop-scroll-strategy'; @@ -25,16 +25,14 @@ import { */ @Injectable({providedIn: 'root'}) export class ScrollStrategyOptions { - private _document: Document; - - constructor( - private _scrollDispatcher: ScrollDispatcher, - private _viewportRuler: ViewportRuler, - private _ngZone: NgZone, - @Inject(DOCUMENT) document: any, - ) { - this._document = document; - } + private _scrollDispatcher = inject(ScrollDispatcher); + private _viewportRuler = inject(ViewportRuler); + private _ngZone = inject(NgZone); + + private _document = inject(DOCUMENT); + + constructor(...args: unknown[]); + constructor() {} /** Do nothing on scroll. */ noop = () => new NoopScrollStrategy(); diff --git a/src/cdk/portal/portal-directives.ts b/src/cdk/portal/portal-directives.ts index b803ab93f01e..bd8f3199542f 100644 --- a/src/cdk/portal/portal-directives.ts +++ b/src/cdk/portal/portal-directives.ts @@ -18,8 +18,8 @@ import { Output, TemplateRef, ViewContainerRef, - Inject, Input, + inject, } from '@angular/core'; import {DOCUMENT} from '@angular/common'; import {BasePortalOutlet, ComponentPortal, Portal, TemplatePortal, DomPortal} from './portal'; @@ -34,7 +34,12 @@ import {BasePortalOutlet, ComponentPortal, Portal, TemplatePortal, DomPortal} fr standalone: true, }) export class CdkPortal extends TemplatePortal { - constructor(templateRef: TemplateRef, viewContainerRef: ViewContainerRef) { + constructor(...args: unknown[]); + + constructor() { + const templateRef = inject>(TemplateRef); + const viewContainerRef = inject(ViewContainerRef); + super(templateRef, viewContainerRef); } } @@ -74,7 +79,9 @@ export type CdkPortalOutletAttachedRef = ComponentRef | EmbeddedViewRef { beforeEach(() => { fixture = TestBed.createComponent(PortalTestApp); fixture.detectChanges(); - - inject([ComponentFactoryResolver], (cfr: ComponentFactoryResolver) => { - componentFactoryResolver = cfr; - })(); + componentFactoryResolver = TestBed.inject(ComponentFactoryResolver); }); it('should load a component into the portal', () => { @@ -502,15 +499,11 @@ describe('Portals', () => { let host: DomPortalOutlet; let injector: Injector; let appRef: ApplicationRef; - let deps = [ComponentFactoryResolver, Injector, ApplicationRef]; - - beforeEach(inject(deps, (cfr: ComponentFactoryResolver, i: Injector, ar: ApplicationRef) => { - componentFactoryResolver = cfr; - injector = i; - appRef = ar; - })); beforeEach(() => { + componentFactoryResolver = TestBed.inject(ComponentFactoryResolver); + injector = TestBed.inject(Injector); + appRef = TestBed.inject(ApplicationRef); someDomElement = document.createElement('div'); host = new DomPortalOutlet( someDomElement, @@ -777,7 +770,7 @@ class ChocolateInjector { imports: [PortalModule, CommonModule], }) class PizzaMsg { - constructor(@Optional() public snack: Chocolate) {} + snack = inject(Chocolate, {optional: true}); } /** @@ -789,9 +782,9 @@ class PizzaMsg { standalone: true, }) class SaveParentNodeOnInit implements AfterViewInit { - parentOnViewInit: HTMLElement; + private _elementRef = inject>(ElementRef); - constructor(private _elementRef: ElementRef) {} + parentOnViewInit: HTMLElement; ngAfterViewInit() { this.parentOnViewInit = this._elementRef.nativeElement.parentElement!; @@ -812,13 +805,11 @@ class SaveParentNodeOnInit implements AfterViewInit { imports: [SaveParentNodeOnInit], }) class ArbitraryViewContainerRefComponent { + viewContainerRef = inject(ViewContainerRef); + injector = inject(Injector); + @ViewChild('template') template: TemplateRef; @ViewChild(SaveParentNodeOnInit) saveParentNodeOnInit: SaveParentNodeOnInit; - - constructor( - public viewContainerRef: ViewContainerRef, - public injector: Injector, - ) {} } /** Test-bed component that contains a portal outlet and a couple of template portals. */ @@ -856,6 +847,9 @@ class ArbitraryViewContainerRefComponent { imports: [CdkPortal, CdkPortalOutlet, PizzaMsg], }) class PortalTestApp { + viewContainerRef = inject(ViewContainerRef); + injector = inject(Injector); + @ViewChildren(CdkPortal) portals: QueryList; @ViewChild(CdkPortalOutlet) portalOutlet: CdkPortalOutlet; @ViewChild('templateRef', {read: TemplateRef}) templateRef: TemplateRef; @@ -868,11 +862,6 @@ class PortalTestApp { fruits = ['Apple', 'Pineapple', 'Durian']; attachedSpy = jasmine.createSpy('attached spy'); - constructor( - public viewContainerRef: ViewContainerRef, - public injector: Injector, - ) {} - get cakePortal() { return this.portals.first; } diff --git a/src/cdk/scrolling/scroll-dispatcher.ts b/src/cdk/scrolling/scroll-dispatcher.ts index 5e30e0580f31..a9069aaf39a8 100644 --- a/src/cdk/scrolling/scroll-dispatcher.ts +++ b/src/cdk/scrolling/scroll-dispatcher.ts @@ -8,7 +8,7 @@ import {coerceElement} from '@angular/cdk/coercion'; import {Platform} from '@angular/cdk/platform'; -import {ElementRef, Injectable, NgZone, OnDestroy, Optional, Inject} from '@angular/core'; +import {ElementRef, Injectable, NgZone, OnDestroy, inject} from '@angular/core'; import {fromEvent, of as observableOf, Subject, Subscription, Observable, Observer} from 'rxjs'; import {auditTime, filter} from 'rxjs/operators'; import type {CdkScrollable} from './scrollable'; @@ -23,16 +23,14 @@ export const DEFAULT_SCROLL_TIME = 20; */ @Injectable({providedIn: 'root'}) export class ScrollDispatcher implements OnDestroy { + private _ngZone = inject(NgZone); + private _platform = inject(Platform); + /** Used to reference correct document/window */ - protected _document: Document; - - constructor( - private _ngZone: NgZone, - private _platform: Platform, - @Optional() @Inject(DOCUMENT) document: any, - ) { - this._document = document; - } + protected _document = inject(DOCUMENT, {optional: true})!; + + constructor(...args: unknown[]); + constructor() {} /** Subject for notifying that a registered scrollable reference element has been scrolled. */ private readonly _scrolled = new Subject(); diff --git a/src/cdk/scrolling/scrollable.ts b/src/cdk/scrolling/scrollable.ts index d0f520d05afc..ea314bb7dea8 100644 --- a/src/cdk/scrolling/scrollable.ts +++ b/src/cdk/scrolling/scrollable.ts @@ -12,7 +12,7 @@ import { RtlScrollAxisType, supportsScrollBehavior, } from '@angular/cdk/platform'; -import {Directive, ElementRef, NgZone, OnDestroy, OnInit, Optional} from '@angular/core'; +import {Directive, ElementRef, NgZone, OnDestroy, OnInit, inject} from '@angular/core'; import {fromEvent, Observable, Subject, Observer} from 'rxjs'; import {takeUntil} from 'rxjs/operators'; import {ScrollDispatcher} from './scroll-dispatcher'; @@ -46,6 +46,11 @@ export type ExtendedScrollToOptions = _XAxis & _YAxis & ScrollOptions; standalone: true, }) export class CdkScrollable implements OnInit, OnDestroy { + protected elementRef = inject>(ElementRef); + protected scrollDispatcher = inject(ScrollDispatcher); + protected ngZone = inject(NgZone); + protected dir? = inject(Directionality, {optional: true}); + protected readonly _destroyed = new Subject(); protected _elementScrolled: Observable = new Observable((observer: Observer) => @@ -56,12 +61,8 @@ export class CdkScrollable implements OnInit, OnDestroy { ), ); - constructor( - protected elementRef: ElementRef, - protected scrollDispatcher: ScrollDispatcher, - protected ngZone: NgZone, - @Optional() protected dir?: Directionality, - ) {} + constructor(...args: unknown[]); + constructor() {} ngOnInit() { this.scrollDispatcher.register(this); diff --git a/src/cdk/scrolling/viewport-ruler.ts b/src/cdk/scrolling/viewport-ruler.ts index f3b6728be067..5a394cd47682 100644 --- a/src/cdk/scrolling/viewport-ruler.ts +++ b/src/cdk/scrolling/viewport-ruler.ts @@ -7,7 +7,7 @@ */ import {Platform} from '@angular/cdk/platform'; -import {Injectable, NgZone, OnDestroy, Optional, Inject} from '@angular/core'; +import {Injectable, NgZone, OnDestroy, inject} from '@angular/core'; import {Observable, Subject} from 'rxjs'; import {auditTime} from 'rxjs/operators'; import {DOCUMENT} from '@angular/common'; @@ -27,6 +27,8 @@ export interface ViewportScrollPosition { */ @Injectable({providedIn: 'root'}) export class ViewportRuler implements OnDestroy { + private _platform = inject(Platform); + /** Cached viewport dimensions. */ private _viewportSize: {width: number; height: number} | null; @@ -39,17 +41,15 @@ export class ViewportRuler implements OnDestroy { }; /** Used to reference correct document/window */ - protected _document: Document; + protected _document = inject(DOCUMENT, {optional: true})!; + + constructor(...args: unknown[]); - constructor( - private _platform: Platform, - ngZone: NgZone, - @Optional() @Inject(DOCUMENT) document: any, - ) { - this._document = document; + constructor() { + const ngZone = inject(NgZone); ngZone.runOutsideAngular(() => { - if (_platform.isBrowser) { + if (this._platform.isBrowser) { const window = this._getWindow(); // Note that bind the events ourselves, rather than going through something like RxJS's diff --git a/src/cdk/scrolling/virtual-for-of.ts b/src/cdk/scrolling/virtual-for-of.ts index 0407383f97a5..9538eec09b6e 100644 --- a/src/cdk/scrolling/virtual-for-of.ts +++ b/src/cdk/scrolling/virtual-for-of.ts @@ -20,7 +20,6 @@ import { Directive, DoCheck, EmbeddedViewRef, - Inject, Input, IterableChangeRecord, IterableChanges, @@ -29,10 +28,10 @@ import { NgIterable, NgZone, OnDestroy, - SkipSelf, TemplateRef, TrackByFunction, ViewContainerRef, + inject, } from '@angular/core'; import {NumberInput, coerceNumberProperty} from '@angular/cdk/coercion'; import {Observable, Subject, of as observableOf, isObservable} from 'rxjs'; @@ -87,6 +86,13 @@ function getOffset(orientation: 'horizontal' | 'vertical', direction: 'start' | export class CdkVirtualForOf implements CdkVirtualScrollRepeater, CollectionViewer, DoCheck, OnDestroy { + private _viewContainerRef = inject(ViewContainerRef); + private _template = inject>>(TemplateRef); + private _differs = inject(IterableDiffers); + private _viewRepeater = + inject<_RecycleViewRepeaterStrategy>>(_VIEW_REPEATER_STRATEGY); + private _viewport = inject(CdkVirtualScrollViewport, {skipSelf: true}); + /** Emits when the rendered view of the data changes. */ readonly viewChange = new Subject(); @@ -180,20 +186,11 @@ export class CdkVirtualForOf private readonly _destroyed = new Subject(); - constructor( - /** The view container to add items to. */ - private _viewContainerRef: ViewContainerRef, - /** The template to use when stamping out new items. */ - private _template: TemplateRef>, - /** The set of available differs. */ - private _differs: IterableDiffers, - /** The strategy used to render items in the virtual scroll viewport. */ - @Inject(_VIEW_REPEATER_STRATEGY) - private _viewRepeater: _RecycleViewRepeaterStrategy>, - /** The virtual scrolling viewport that these items are being rendered in. */ - @SkipSelf() private _viewport: CdkVirtualScrollViewport, - ngZone: NgZone, - ) { + constructor(...args: unknown[]); + + constructor() { + const ngZone = inject(NgZone); + this.dataStream.subscribe(data => { this._data = data; this._onRenderedDataChange(); diff --git a/src/cdk/scrolling/virtual-scroll-viewport.spec.ts b/src/cdk/scrolling/virtual-scroll-viewport.spec.ts index de6e7072ac02..dd6087c7dec7 100644 --- a/src/cdk/scrolling/virtual-scroll-viewport.spec.ts +++ b/src/cdk/scrolling/virtual-scroll-viewport.spec.ts @@ -15,13 +15,13 @@ import { ViewChild, ViewContainerRef, ViewEncapsulation, + inject, } from '@angular/core'; import { ComponentFixture, TestBed, fakeAsync, flush, - inject, tick, waitForAsync, } from '@angular/core/testing'; @@ -787,16 +787,15 @@ describe('CdkVirtualScrollViewport', () => { ); })); - it('should register and degregister with ScrollDispatcher', fakeAsync( - inject([ScrollDispatcher], (dispatcher: ScrollDispatcher) => { - spyOn(dispatcher, 'register').and.callThrough(); - spyOn(dispatcher, 'deregister').and.callThrough(); - finishInit(fixture); - expect(dispatcher.register).toHaveBeenCalledWith(testComponent.viewport.scrollable); - fixture.destroy(); - expect(dispatcher.deregister).toHaveBeenCalledWith(testComponent.viewport.scrollable); - }), - )); + it('should register and degregister with ScrollDispatcher', fakeAsync(() => { + const dispatcher = TestBed.inject(ScrollDispatcher); + spyOn(dispatcher, 'register').and.callThrough(); + spyOn(dispatcher, 'deregister').and.callThrough(); + finishInit(fixture); + expect(dispatcher.register).toHaveBeenCalledWith(testComponent.viewport.scrollable!); + fixture.destroy(); + expect(dispatcher.deregister).toHaveBeenCalledWith(testComponent.viewport.scrollable!); + })); it('should not throw when disposing of a view that will not fit in the cache', fakeAsync(() => { finishInit(fixture); @@ -819,9 +818,9 @@ describe('CdkVirtualScrollViewport', () => { describe('viewChange change detection behavior', () => { let appRef: ApplicationRef; - beforeEach(inject([ApplicationRef], (ar: ApplicationRef) => { - appRef = ar; - })); + beforeEach(() => { + appRef = TestBed.inject(ApplicationRef); + }); it('should not run change detection if there are no viewChange listeners', fakeAsync(() => { finishInit(fixture); @@ -1207,7 +1206,7 @@ function triggerScroll(viewport: CdkVirtualScrollViewport, offset?: number) { if (offset !== undefined) { viewport.scrollToOffset(offset); } - dispatchFakeEvent(viewport.scrollable.getElementRef().nativeElement, 'scroll'); + dispatchFakeEvent(viewport.scrollable!.getElementRef().nativeElement, 'scroll'); tick(16); // flush animation frame } @@ -1373,7 +1372,7 @@ class VirtualScrollWithNoStrategy { standalone: true, }) class InjectsViewContainer { - constructor(public viewContainerRef: ViewContainerRef) {} + viewContainerRef = inject(ViewContainerRef); } @Component({ diff --git a/src/cdk/scrolling/virtual-scroll-viewport.ts b/src/cdk/scrolling/virtual-scroll-viewport.ts index 7266e24db197..b86ea0bcb281 100644 --- a/src/cdk/scrolling/virtual-scroll-viewport.ts +++ b/src/cdk/scrolling/virtual-scroll-viewport.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import {Directionality} from '@angular/cdk/bidi'; import {ListRange} from '@angular/cdk/collections'; import {Platform} from '@angular/cdk/platform'; import { @@ -20,7 +19,6 @@ import { Inject, Injector, Input, - NgZone, OnDestroy, OnInit, Optional, @@ -37,7 +35,6 @@ import { Subscription, } from 'rxjs'; import {auditTime, startWith, takeUntil} from 'rxjs/operators'; -import {ScrollDispatcher} from './scroll-dispatcher'; import {CdkScrollable, ExtendedScrollToOptions} from './scrollable'; import {ViewportRuler} from './viewport-ruler'; import {CdkVirtualScrollRepeater} from './virtual-scroll-repeater'; @@ -82,6 +79,13 @@ const SCROLL_SCHEDULER = ], }) export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements OnInit, OnDestroy { + override elementRef = inject>(ElementRef); + private _changeDetectorRef = inject(ChangeDetectorRef); + private _scrollStrategy = inject(VIRTUAL_SCROLL_STRATEGY, { + optional: true, + })!; + scrollable = inject(VIRTUAL_SCROLLABLE, {optional: true})!; + private _platform = inject(Platform); /** Emits when the viewport is detached from a CdkVirtualForOf. */ @@ -179,21 +183,13 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On private _isDestroyed = false; - constructor( - public override elementRef: ElementRef, - private _changeDetectorRef: ChangeDetectorRef, - ngZone: NgZone, - @Optional() - @Inject(VIRTUAL_SCROLL_STRATEGY) - private _scrollStrategy: VirtualScrollStrategy, - @Optional() dir: Directionality, - scrollDispatcher: ScrollDispatcher, - viewportRuler: ViewportRuler, - @Optional() @Inject(VIRTUAL_SCROLLABLE) public scrollable: CdkVirtualScrollable, - ) { - super(elementRef, scrollDispatcher, ngZone, dir); - - if (!_scrollStrategy && (typeof ngDevMode === 'undefined' || ngDevMode)) { + constructor(...args: unknown[]); + + constructor() { + super(); + const viewportRuler = inject(ViewportRuler); + + if (!this._scrollStrategy && (typeof ngDevMode === 'undefined' || ngDevMode)) { throw Error('Error: cdk-virtual-scroll-viewport requires the "itemSize" property to be set.'); } diff --git a/src/cdk/scrolling/virtual-scrollable-element.ts b/src/cdk/scrolling/virtual-scrollable-element.ts index 8ab9c81459ac..7d0353ce31e1 100644 --- a/src/cdk/scrolling/virtual-scrollable-element.ts +++ b/src/cdk/scrolling/virtual-scrollable-element.ts @@ -6,9 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Directionality} from '@angular/cdk/bidi'; -import {Directive, ElementRef, NgZone, Optional} from '@angular/core'; -import {ScrollDispatcher} from './scroll-dispatcher'; +import {Directive} from '@angular/core'; import {CdkVirtualScrollable, VIRTUAL_SCROLLABLE} from './virtual-scrollable'; /** @@ -23,13 +21,10 @@ import {CdkVirtualScrollable, VIRTUAL_SCROLLABLE} from './virtual-scrollable'; }, }) export class CdkVirtualScrollableElement extends CdkVirtualScrollable { - constructor( - elementRef: ElementRef, - scrollDispatcher: ScrollDispatcher, - ngZone: NgZone, - @Optional() dir: Directionality, - ) { - super(elementRef, scrollDispatcher, ngZone, dir); + constructor(...args: unknown[]); + + constructor() { + super(); } override measureBoundingClientRectWithScrollOffset( diff --git a/src/cdk/scrolling/virtual-scrollable-window.ts b/src/cdk/scrolling/virtual-scrollable-window.ts index 63eaf88c915e..bba72b73f6c6 100644 --- a/src/cdk/scrolling/virtual-scrollable-window.ts +++ b/src/cdk/scrolling/virtual-scrollable-window.ts @@ -6,11 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -import {Directionality} from '@angular/cdk/bidi'; -import {Directive, ElementRef, NgZone, Optional} from '@angular/core'; +import {Directive, ElementRef} from '@angular/core'; import {fromEvent, Observable, Observer} from 'rxjs'; import {takeUntil} from 'rxjs/operators'; -import {ScrollDispatcher} from './scroll-dispatcher'; import {CdkVirtualScrollable, VIRTUAL_SCROLLABLE} from './virtual-scrollable'; /** @@ -29,8 +27,11 @@ export class CdkVirtualScrollableWindow extends CdkVirtualScrollable { ), ); - constructor(scrollDispatcher: ScrollDispatcher, ngZone: NgZone, @Optional() dir: Directionality) { - super(new ElementRef(document.documentElement), scrollDispatcher, ngZone, dir); + constructor(...args: unknown[]); + + constructor() { + super(); + this.elementRef = new ElementRef(document.documentElement); } override measureBoundingClientRectWithScrollOffset( diff --git a/src/cdk/scrolling/virtual-scrollable.ts b/src/cdk/scrolling/virtual-scrollable.ts index 12c3b44323ab..1634da8867b5 100644 --- a/src/cdk/scrolling/virtual-scrollable.ts +++ b/src/cdk/scrolling/virtual-scrollable.ts @@ -6,9 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Directionality} from '@angular/cdk/bidi'; -import {Directive, ElementRef, InjectionToken, NgZone, Optional} from '@angular/core'; -import {ScrollDispatcher} from './scroll-dispatcher'; +import {Directive, InjectionToken} from '@angular/core'; import {CdkScrollable} from './scrollable'; export const VIRTUAL_SCROLLABLE = new InjectionToken('VIRTUAL_SCROLLABLE'); @@ -18,13 +16,9 @@ export const VIRTUAL_SCROLLABLE = new InjectionToken('VIRT */ @Directive() export abstract class CdkVirtualScrollable extends CdkScrollable { - constructor( - elementRef: ElementRef, - scrollDispatcher: ScrollDispatcher, - ngZone: NgZone, - @Optional() dir?: Directionality, - ) { - super(elementRef, scrollDispatcher, ngZone, dir); + constructor(...args: unknown[]); + constructor() { + super(); } /** diff --git a/src/cdk/stepper/step-header.ts b/src/cdk/stepper/step-header.ts index 1e37c30eb138..9a43797b5d33 100644 --- a/src/cdk/stepper/step-header.ts +++ b/src/cdk/stepper/step-header.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Directive, ElementRef} from '@angular/core'; +import {Directive, ElementRef, inject} from '@angular/core'; import {FocusableOption} from '@angular/cdk/a11y'; @Directive({ @@ -17,7 +17,10 @@ import {FocusableOption} from '@angular/cdk/a11y'; standalone: true, }) export class CdkStepHeader implements FocusableOption { - constructor(public _elementRef: ElementRef) {} + _elementRef = inject>(ElementRef); + + constructor(...args: unknown[]); + constructor() {} /** Focuses the step header. */ focus() { diff --git a/src/cdk/stepper/step-label.ts b/src/cdk/stepper/step-label.ts index 2502a5b986e6..d6843411cd4d 100644 --- a/src/cdk/stepper/step-label.ts +++ b/src/cdk/stepper/step-label.ts @@ -6,12 +6,15 @@ * found in the LICENSE file at https://angular.io/license */ -import {Directive, TemplateRef} from '@angular/core'; +import {Directive, TemplateRef, inject} from '@angular/core'; @Directive({ selector: '[cdkStepLabel]', standalone: true, }) export class CdkStepLabel { - constructor(/** @docs-private */ public template: TemplateRef) {} + template = inject>(TemplateRef); + + constructor(...args: unknown[]); + constructor() {} } diff --git a/src/cdk/stepper/stepper-button.ts b/src/cdk/stepper/stepper-button.ts index 913dd7f9ab31..ff5743893db8 100644 --- a/src/cdk/stepper/stepper-button.ts +++ b/src/cdk/stepper/stepper-button.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Directive, Input} from '@angular/core'; +import {Directive, Input, inject} from '@angular/core'; import {CdkStepper} from './stepper'; @@ -20,10 +20,13 @@ import {CdkStepper} from './stepper'; standalone: true, }) export class CdkStepperNext { + _stepper = inject(CdkStepper); + /** Type of the next button. Defaults to "submit" if not specified. */ @Input() type: string = 'submit'; - constructor(public _stepper: CdkStepper) {} + constructor(...args: unknown[]); + constructor() {} } /** Button that moves to the previous step in a stepper workflow. */ @@ -36,8 +39,11 @@ export class CdkStepperNext { standalone: true, }) export class CdkStepperPrevious { + _stepper = inject(CdkStepper); + /** Type of the previous button. Defaults to "button" if not specified. */ @Input() type: string = 'button'; - constructor(public _stepper: CdkStepper) {} + constructor(...args: unknown[]); + constructor() {} } diff --git a/src/cdk/stepper/stepper.ts b/src/cdk/stepper/stepper.ts index 1a7d7851965e..b17613f45e12 100644 --- a/src/cdk/stepper/stepper.ts +++ b/src/cdk/stepper/stepper.ts @@ -19,13 +19,10 @@ import { Directive, ElementRef, EventEmitter, - forwardRef, - Inject, InjectionToken, Input, OnChanges, OnDestroy, - Optional, Output, QueryList, TemplateRef, @@ -34,6 +31,7 @@ import { AfterContentInit, booleanAttribute, numberAttribute, + inject, } from '@angular/core'; import {_getFocusedElementPierceShadowDom} from '@angular/cdk/platform'; import {Observable, of as observableOf, Subject} from 'rxjs'; @@ -109,6 +107,7 @@ export interface StepperOptions { }) export class CdkStep implements OnChanges { private _stepperOptions: StepperOptions; + _stepper = inject(CdkStepper); _displayDefaultIndicatorType: boolean; /** Template for step label if it exists. */ @@ -179,10 +178,10 @@ export class CdkStep implements OnChanges { return this.stepControl && this.stepControl.invalid && this.interacted; } - constructor( - @Inject(forwardRef(() => CdkStepper)) public _stepper: CdkStepper, - @Optional() @Inject(STEPPER_GLOBAL_OPTIONS) stepperOptions?: StepperOptions, - ) { + constructor(...args: unknown[]); + + constructor() { + const stepperOptions = inject(STEPPER_GLOBAL_OPTIONS, {optional: true}); this._stepperOptions = stepperOptions ? stepperOptions : {}; this._displayDefaultIndicatorType = this._stepperOptions.displayDefaultIndicatorType !== false; } @@ -236,6 +235,10 @@ export class CdkStep implements OnChanges { standalone: true, }) export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy { + private _dir = inject(Directionality, {optional: true}); + private _changeDetectorRef = inject(ChangeDetectorRef); + private _elementRef = inject>(ElementRef); + /** Emits when the component is destroyed. */ protected readonly _destroyed = new Subject(); @@ -300,7 +303,7 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy { @Output() readonly selectedIndexChange: EventEmitter = new EventEmitter(); /** Used to track unique ID for each stepper component. */ - _groupId: number; + _groupId = nextId++; /** Orientation of the stepper. */ @Input() @@ -317,13 +320,8 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy { } private _orientation: StepperOrientation = 'horizontal'; - constructor( - @Optional() private _dir: Directionality, - private _changeDetectorRef: ChangeDetectorRef, - private _elementRef: ElementRef, - ) { - this._groupId = nextId++; - } + constructor(...args: unknown[]); + constructor() {} ngAfterContentInit() { this._steps.changes diff --git a/src/cdk/table/cell.ts b/src/cdk/table/cell.ts index 19dd24f5266d..54609c395566 100644 --- a/src/cdk/table/cell.ts +++ b/src/cdk/table/cell.ts @@ -10,11 +10,10 @@ import { ContentChild, Directive, ElementRef, - Inject, Input, - Optional, TemplateRef, booleanAttribute, + inject, } from '@angular/core'; import {CanStick} from './can-stick'; import {CDK_TABLE} from './tokens'; @@ -33,7 +32,11 @@ export interface CellDef { standalone: true, }) export class CdkCellDef implements CellDef { - constructor(/** @docs-private */ public template: TemplateRef) {} + /** @docs-private */ + template = inject>(TemplateRef); + + constructor(...args: unknown[]); + constructor() {} } /** @@ -45,7 +48,11 @@ export class CdkCellDef implements CellDef { standalone: true, }) export class CdkHeaderCellDef implements CellDef { - constructor(/** @docs-private */ public template: TemplateRef) {} + /** @docs-private */ + template = inject>(TemplateRef); + + constructor(...args: unknown[]); + constructor() {} } /** @@ -57,7 +64,11 @@ export class CdkHeaderCellDef implements CellDef { standalone: true, }) export class CdkFooterCellDef implements CellDef { - constructor(/** @docs-private */ public template: TemplateRef) {} + /** @docs-private */ + template = inject>(TemplateRef); + + constructor(...args: unknown[]); + constructor() {} } /** @@ -70,6 +81,8 @@ export class CdkFooterCellDef implements CellDef { standalone: true, }) export class CdkColumnDef implements CanStick { + _table? = inject(CDK_TABLE, {optional: true}); + private _hasStickyChanged = false; /** Unique name for this column. */ @@ -134,7 +147,8 @@ export class CdkColumnDef implements CanStick { */ _columnCssClassName: string[]; - constructor(@Inject(CDK_TABLE) @Optional() public _table?: any) {} + constructor(...args: unknown[]); + constructor() {} /** Whether the sticky state has changed. */ hasStickyChanged(): boolean { @@ -193,8 +207,10 @@ export class BaseCdkCell { standalone: true, }) export class CdkHeaderCell extends BaseCdkCell { - constructor(columnDef: CdkColumnDef, elementRef: ElementRef) { - super(columnDef, elementRef); + constructor(...args: unknown[]); + + constructor() { + super(inject(CdkColumnDef), inject(ElementRef)); } } @@ -207,8 +223,14 @@ export class CdkHeaderCell extends BaseCdkCell { standalone: true, }) export class CdkFooterCell extends BaseCdkCell { - constructor(columnDef: CdkColumnDef, elementRef: ElementRef) { + constructor(...args: unknown[]); + + constructor() { + const columnDef = inject(CdkColumnDef); + const elementRef = inject(ElementRef); + super(columnDef, elementRef); + const role = columnDef._table?._getCellRole(); if (role) { elementRef.nativeElement.setAttribute('role', role); @@ -225,8 +247,14 @@ export class CdkFooterCell extends BaseCdkCell { standalone: true, }) export class CdkCell extends BaseCdkCell { - constructor(columnDef: CdkColumnDef, elementRef: ElementRef) { + constructor(...args: unknown[]); + + constructor() { + const columnDef = inject(CdkColumnDef); + const elementRef = inject(ElementRef); + super(columnDef, elementRef); + const role = columnDef._table?._getCellRole(); if (role) { elementRef.nativeElement.setAttribute('role', role); diff --git a/src/cdk/table/coalesced-style-scheduler.ts b/src/cdk/table/coalesced-style-scheduler.ts index 6267b3614691..31381f3984b5 100644 --- a/src/cdk/table/coalesced-style-scheduler.ts +++ b/src/cdk/table/coalesced-style-scheduler.ts @@ -33,7 +33,8 @@ export class _CoalescedStyleScheduler { private _currentSchedule: _Schedule | null = null; private _ngZone = inject(NgZone); - constructor(_unusedNgZone?: NgZone) {} + constructor(...args: unknown[]); + constructor() {} /** * Schedules the specified task to run at the end of the current VM turn. diff --git a/src/cdk/table/row.ts b/src/cdk/table/row.ts index 017e88b7b450..af47a97cc435 100644 --- a/src/cdk/table/row.ts +++ b/src/cdk/table/row.ts @@ -19,10 +19,9 @@ import { TemplateRef, ViewContainerRef, ViewEncapsulation, - Inject, - Optional, Input, booleanAttribute, + inject, } from '@angular/core'; import {CanStick} from './can-stick'; import {CdkCellDef, CdkColumnDef} from './cell'; @@ -40,16 +39,17 @@ export const CDK_ROW_TEMPLATE = ``; */ @Directive() export abstract class BaseRowDef implements OnChanges { + template = inject>(TemplateRef); + protected _differs = inject(IterableDiffers); + /** The columns to be displayed on this row. */ columns: Iterable; /** Differ used to check if any changes were made to the columns. */ protected _columnsDiffer: IterableDiffer; - constructor( - /** @docs-private */ public template: TemplateRef, - protected _differs: IterableDiffers, - ) {} + constructor(...args: unknown[]); + constructor() {} ngOnChanges(changes: SimpleChanges): void { // Create a new columns differ if one does not yet exist. Initialize it based on initial value @@ -92,6 +92,8 @@ export abstract class BaseRowDef implements OnChanges { standalone: true, }) export class CdkHeaderRowDef extends BaseRowDef implements CanStick, OnChanges { + _table? = inject(CDK_TABLE, {optional: true}); + private _hasStickyChanged = false; /** Whether the row is sticky. */ @@ -107,12 +109,10 @@ export class CdkHeaderRowDef extends BaseRowDef implements CanStick, OnChanges { } private _sticky = false; - constructor( - template: TemplateRef, - _differs: IterableDiffers, - @Inject(CDK_TABLE) @Optional() public _table?: any, - ) { - super(template, _differs); + constructor(...args: unknown[]); + + constructor() { + super(inject>(TemplateRef), inject(IterableDiffers)); } // Prerender fails to recognize that ngOnChanges in a part of this class through inheritance. @@ -144,6 +144,8 @@ export class CdkHeaderRowDef extends BaseRowDef implements CanStick, OnChanges { standalone: true, }) export class CdkFooterRowDef extends BaseRowDef implements CanStick, OnChanges { + _table? = inject(CDK_TABLE, {optional: true}); + private _hasStickyChanged = false; /** Whether the row is sticky. */ @@ -159,12 +161,10 @@ export class CdkFooterRowDef extends BaseRowDef implements CanStick, OnChanges { } private _sticky = false; - constructor( - template: TemplateRef, - _differs: IterableDiffers, - @Inject(CDK_TABLE) @Optional() public _table?: any, - ) { - super(template, _differs); + constructor(...args: unknown[]); + + constructor() { + super(inject>(TemplateRef), inject(IterableDiffers)); } // Prerender fails to recognize that ngOnChanges in a part of this class through inheritance. @@ -200,6 +200,8 @@ export class CdkFooterRowDef extends BaseRowDef implements CanStick, OnChanges { standalone: true, }) export class CdkRowDef extends BaseRowDef { + _table? = inject(CDK_TABLE, {optional: true}); + /** * Function that should return true if this row template should be used for the provided index * and row data. If left undefined, this row will be considered the default row template to use @@ -208,14 +210,12 @@ export class CdkRowDef extends BaseRowDef { */ when: (index: number, rowData: T) => boolean; - // TODO(andrewseguin): Add an input for providing a switch function to determine - // if this template should be used. - constructor( - template: TemplateRef, - _differs: IterableDiffers, - @Inject(CDK_TABLE) @Optional() public _table?: any, - ) { - super(template, _differs); + constructor(...args: unknown[]); + + constructor() { + // TODO(andrewseguin): Add an input for providing a switch function to determine + // if this template should be used. + super(inject>(TemplateRef), inject(IterableDiffers)); } } @@ -283,6 +283,8 @@ export interface CdkCellOutletMultiRowContext { standalone: true, }) export class CdkCellOutlet implements OnDestroy { + _viewContainer = inject(ViewContainerRef); + /** The ordered list of cells to render within this outlet's view container */ cells: CdkCellDef[]; @@ -298,7 +300,9 @@ export class CdkCellOutlet implements OnDestroy { */ static mostRecentCellOutlet: CdkCellOutlet | null = null; - constructor(public _viewContainer: ViewContainerRef) { + constructor(...args: unknown[]); + + constructor() { CdkCellOutlet.mostRecentCellOutlet = this; } @@ -368,6 +372,10 @@ export class CdkRow {} standalone: true, }) export class CdkNoDataRow { + templateRef = inject>(TemplateRef); + _contentClassName = 'cdk-no-data-row'; - constructor(public templateRef: TemplateRef) {} + + constructor(...args: unknown[]); + constructor() {} } diff --git a/src/cdk/table/table.ts b/src/cdk/table/table.ts index 940ba164e738..55e734a42564 100644 --- a/src/cdk/table/table.ts +++ b/src/cdk/table/table.ts @@ -25,7 +25,6 @@ import {DOCUMENT} from '@angular/common'; import { AfterContentChecked, AfterContentInit, - Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, @@ -35,18 +34,14 @@ import { ElementRef, EmbeddedViewRef, EventEmitter, - Inject, Input, IterableChangeRecord, IterableDiffer, IterableDiffers, - NgZone, OnDestroy, OnInit, - Optional, Output, QueryList, - SkipSelf, TemplateRef, TrackByFunction, ViewContainerRef, @@ -55,6 +50,7 @@ import { inject, afterNextRender, Injector, + HostAttributeToken, } from '@angular/core'; import { BehaviorSubject, @@ -117,10 +113,12 @@ export type CdkTableDataSourceInput = readonly T[] | DataSource | Observab standalone: true, }) export class DataRowOutlet implements RowOutlet { - constructor( - public viewContainer: ViewContainerRef, - public elementRef: ElementRef, - ) { + viewContainer = inject(ViewContainerRef); + elementRef = inject(ElementRef); + + constructor(...args: unknown[]); + + constructor() { const table = inject>(CDK_TABLE); table._rowOutlet = this; table._outletAssigned(); @@ -136,10 +134,12 @@ export class DataRowOutlet implements RowOutlet { standalone: true, }) export class HeaderRowOutlet implements RowOutlet { - constructor( - public viewContainer: ViewContainerRef, - public elementRef: ElementRef, - ) { + viewContainer = inject(ViewContainerRef); + elementRef = inject(ElementRef); + + constructor(...args: unknown[]); + + constructor() { const table = inject>(CDK_TABLE); table._headerRowOutlet = this; table._outletAssigned(); @@ -155,10 +155,12 @@ export class HeaderRowOutlet implements RowOutlet { standalone: true, }) export class FooterRowOutlet implements RowOutlet { - constructor( - public viewContainer: ViewContainerRef, - public elementRef: ElementRef, - ) { + viewContainer = inject(ViewContainerRef); + elementRef = inject(ElementRef); + + constructor(...args: unknown[]); + + constructor() { const table = inject>(CDK_TABLE); table._footerRowOutlet = this; table._outletAssigned(); @@ -175,10 +177,12 @@ export class FooterRowOutlet implements RowOutlet { standalone: true, }) export class NoDataRowOutlet implements RowOutlet { - constructor( - public viewContainer: ViewContainerRef, - public elementRef: ElementRef, - ) { + viewContainer = inject(ViewContainerRef); + elementRef = inject(ElementRef); + + constructor(...args: unknown[]); + + constructor() { const table = inject>(CDK_TABLE); table._noDataRowOutlet = this; table._outletAssigned(); @@ -291,7 +295,23 @@ export interface RenderRow { export class CdkTable implements AfterContentInit, AfterContentChecked, CollectionViewer, OnDestroy, OnInit { - private _document: Document; + protected readonly _differs = inject(IterableDiffers); + protected readonly _changeDetectorRef = inject(ChangeDetectorRef); + protected readonly _elementRef = inject(ElementRef); + protected readonly _dir = inject(Directionality, {optional: true}); + private _platform = inject(Platform); + protected readonly _viewRepeater = + inject<_ViewRepeater, RowContext>>(_VIEW_REPEATER_STRATEGY); + protected readonly _coalescedStyleScheduler = inject<_CoalescedStyleScheduler>( + _COALESCED_STYLE_SCHEDULER, + ); + private readonly _viewportRuler = inject(ViewportRuler); + protected readonly _stickyPositioningListener = inject( + STICKY_POSITIONING_LISTENER, + {optional: true, skipSelf: true}, + )!; + + private _document = inject(DOCUMENT); /** Latest data provided by the data source. */ protected _data: readonly T[]; @@ -596,40 +616,17 @@ export class CdkTable private _injector = inject(Injector); - constructor( - protected readonly _differs: IterableDiffers, - protected readonly _changeDetectorRef: ChangeDetectorRef, - protected readonly _elementRef: ElementRef, - @Attribute('role') role: string, - @Optional() protected readonly _dir: Directionality, - @Inject(DOCUMENT) _document: any, - private _platform: Platform, - @Inject(_VIEW_REPEATER_STRATEGY) - protected readonly _viewRepeater: _ViewRepeater, RowContext>, - @Inject(_COALESCED_STYLE_SCHEDULER) - protected readonly _coalescedStyleScheduler: _CoalescedStyleScheduler, - private readonly _viewportRuler: ViewportRuler, - /** - * @deprecated `_stickyPositioningListener` parameter to become required. - * @breaking-change 13.0.0 - */ - @Optional() - @SkipSelf() - @Inject(STICKY_POSITIONING_LISTENER) - protected readonly _stickyPositioningListener: StickyPositioningListener, - /** - * @deprecated `_unusedNgZone` parameter to be removed. - * @breaking-change 19.0.0 - */ - @Optional() _unusedNgZone?: NgZone, - ) { + constructor(...args: unknown[]); + + constructor() { + const role = inject(new HostAttributeToken('role'), {optional: true}); + if (!role) { - _elementRef.nativeElement.setAttribute('role', 'table'); + this._elementRef.nativeElement.setAttribute('role', 'table'); } - this._document = _document; - this._isServer = !_platform.isBrowser; - this._isNativeHtmlTable = _elementRef.nativeElement.nodeName === 'TABLE'; + this._isServer = !this._platform.isBrowser; + this._isNativeHtmlTable = this._elementRef.nativeElement.nodeName === 'TABLE'; } ngOnInit() { diff --git a/src/cdk/table/text-column.ts b/src/cdk/table/text-column.ts index 81a65cc2697f..5c5aa351dfdb 100644 --- a/src/cdk/table/text-column.ts +++ b/src/cdk/table/text-column.ts @@ -9,13 +9,12 @@ import { ChangeDetectionStrategy, Component, - Inject, Input, OnDestroy, OnInit, - Optional, ViewChild, ViewEncapsulation, + inject, } from '@angular/core'; import {CdkCellDef, CdkColumnDef, CdkHeaderCellDef, CdkHeaderCell, CdkCell} from './cell'; import {CdkTable} from './table'; @@ -58,6 +57,9 @@ import {TEXT_COLUMN_OPTIONS, TextColumnOptions} from './tokens'; imports: [CdkColumnDef, CdkHeaderCellDef, CdkHeaderCell, CdkCellDef, CdkCell], }) export class CdkTextColumn implements OnDestroy, OnInit { + private _table = inject>(CdkTable, {optional: true}); + private _options = inject>(TEXT_COLUMN_OPTIONS, {optional: true})!; + /** Column name that should be used to reference this column. */ @Input() get name(): string { @@ -110,14 +112,10 @@ export class CdkTextColumn implements OnDestroy, OnInit { */ @ViewChild(CdkHeaderCellDef, {static: true}) headerCell: CdkHeaderCellDef; - constructor( - // `CdkTextColumn` is always requiring a table, but we just assert it manually - // for better error reporting. - // tslint:disable-next-line: lightweight-tokens - @Optional() private _table: CdkTable, - @Optional() @Inject(TEXT_COLUMN_OPTIONS) private _options: TextColumnOptions, - ) { - this._options = _options || {}; + constructor(...args: unknown[]); + + constructor() { + this._options = this._options || {}; } ngOnInit() { diff --git a/src/cdk/testing/tests/test-main-component.ts b/src/cdk/testing/tests/test-main-component.ts index 0905f15fc606..65d02511f6eb 100644 --- a/src/cdk/testing/tests/test-main-component.ts +++ b/src/cdk/testing/tests/test-main-component.ts @@ -18,6 +18,7 @@ import { OnDestroy, ViewChild, ViewEncapsulation, + inject, } from '@angular/core'; import {TestShadowBoundary} from './test-shadow-boundary'; import {TestSubComponent} from './test-sub-component'; @@ -31,6 +32,9 @@ import {TestSubComponent} from './test-sub-component'; imports: [TestShadowBoundary, TestSubComponent, FormsModule, ReactiveFormsModule], }) export class TestMainComponent implements OnDestroy { + private _cdr = inject(ChangeDetectorRef); + private _zone = inject(NgZone); + username: string; counter: number; asyncCounter: number; @@ -58,10 +62,7 @@ export class TestMainComponent implements OnDestroy { private _fakeOverlayElement: HTMLElement; - constructor( - private _cdr: ChangeDetectorRef, - private _zone: NgZone, - ) { + constructor() { this.username = 'Yi'; this.counter = 0; this.asyncCounter = 0; diff --git a/src/cdk/text-field/autofill.ts b/src/cdk/text-field/autofill.ts index 7717dd0d167e..5ef7cc4ad6aa 100644 --- a/src/cdk/text-field/autofill.ts +++ b/src/cdk/text-field/autofill.ts @@ -47,13 +47,14 @@ const listenerOptions = normalizePassiveListenerOptions({passive: true}); */ @Injectable({providedIn: 'root'}) export class AutofillMonitor implements OnDestroy { + private _platform = inject(Platform); + private _ngZone = inject(NgZone); + private _styleLoader = inject(_CdkPrivateStyleLoader); private _monitoredElements = new Map(); - constructor( - private _platform: Platform, - private _ngZone: NgZone, - ) {} + constructor(...args: unknown[]); + constructor() {} /** * Monitor for changes in the autofill state of the given input element. @@ -155,13 +156,14 @@ export class AutofillMonitor implements OnDestroy { standalone: true, }) export class CdkAutofill implements OnDestroy, OnInit { + private _elementRef = inject>(ElementRef); + private _autofillMonitor = inject(AutofillMonitor); + /** Emits when the autofill state of the element changes. */ @Output() readonly cdkAutofill = new EventEmitter(); - constructor( - private _elementRef: ElementRef, - private _autofillMonitor: AutofillMonitor, - ) {} + constructor(...args: unknown[]); + constructor() {} ngOnInit() { this._autofillMonitor diff --git a/src/cdk/text-field/autosize.ts b/src/cdk/text-field/autosize.ts index c3b784851796..c93e5bf4331a 100644 --- a/src/cdk/text-field/autosize.ts +++ b/src/cdk/text-field/autosize.ts @@ -15,8 +15,6 @@ import { DoCheck, OnDestroy, NgZone, - Optional, - Inject, booleanAttribute, inject, } from '@angular/core'; @@ -41,6 +39,10 @@ import {_CdkTextFieldStyleLoader} from './text-field-style-loader'; standalone: true, }) export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy { + private _elementRef = inject>(ElementRef); + private _platform = inject(Platform); + private _ngZone = inject(NgZone); + /** Keep track of the previous textarea value to avoid resizing when the value hasn't changed. */ private _previousValue?: string; private _initialHeight: string | undefined; @@ -114,22 +116,17 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy { private _cachedPlaceholderHeight?: number; /** Used to reference correct document/window */ - protected _document?: Document; + protected _document? = inject(DOCUMENT, {optional: true}); private _hasFocus: boolean; private _isViewInited = false; - constructor( - private _elementRef: ElementRef, - private _platform: Platform, - private _ngZone: NgZone, - /** @breaking-change 11.0.0 make document required */ - @Optional() @Inject(DOCUMENT) document?: any, - ) { + constructor(...args: unknown[]); + + constructor() { const styleLoader = inject(_CdkPrivateStyleLoader); styleLoader.load(_CdkTextFieldStyleLoader); - this._document = document; this._textareaElement = this._elementRef.nativeElement as HTMLTextAreaElement; } diff --git a/src/cdk/tree/nested-node.ts b/src/cdk/tree/nested-node.ts index ad10a24fad13..8ab7e5853a00 100644 --- a/src/cdk/tree/nested-node.ts +++ b/src/cdk/tree/nested-node.ts @@ -9,17 +9,17 @@ import { AfterContentInit, ContentChildren, Directive, - ElementRef, IterableDiffer, IterableDiffers, OnDestroy, OnInit, QueryList, + inject, } from '@angular/core'; import {takeUntil} from 'rxjs/operators'; import {CDK_TREE_NODE_OUTLET_NODE, CdkTreeNodeOutlet} from './outlet'; -import {CdkTree, CdkTreeNode} from './tree'; +import {CdkTreeNode} from './tree'; /** * Nested node is a child of ``. It works with nested tree. @@ -43,6 +43,8 @@ export class CdkNestedTreeNode extends CdkTreeNode implements AfterContentInit, OnDestroy, OnInit { + protected _differs = inject(IterableDiffers); + /** Differ used to find the changes in the data provided by the data source. */ private _dataDiffer: IterableDiffer; @@ -57,12 +59,10 @@ export class CdkNestedTreeNode }) nodeOutlet: QueryList; - constructor( - elementRef: ElementRef, - tree: CdkTree, - protected _differs: IterableDiffers, - ) { - super(elementRef, tree); + constructor(...args: unknown[]); + + constructor() { + super(); } ngAfterContentInit() { diff --git a/src/cdk/tree/node.ts b/src/cdk/tree/node.ts index f0a2ad65a4d6..69010d8f537a 100644 --- a/src/cdk/tree/node.ts +++ b/src/cdk/tree/node.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Directive, TemplateRef} from '@angular/core'; +import {Directive, TemplateRef, inject} from '@angular/core'; /** Context provided to the tree node component. */ export class CdkTreeNodeOutletContext { @@ -37,6 +37,9 @@ export class CdkTreeNodeOutletContext { standalone: true, }) export class CdkTreeNodeDef { + /** @docs-private */ + template = inject>(TemplateRef); + /** * Function that should return true if this node template should be used for the provided node * data and index. If left undefined, this node will be considered the default node template to @@ -46,6 +49,6 @@ export class CdkTreeNodeDef { */ when: (index: number, nodeData: T) => boolean; - /** @docs-private */ - constructor(public template: TemplateRef) {} + constructor(...args: unknown[]); + constructor() {} } diff --git a/src/cdk/tree/outlet.ts b/src/cdk/tree/outlet.ts index 10fadb697c0d..10fee886115f 100644 --- a/src/cdk/tree/outlet.ts +++ b/src/cdk/tree/outlet.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {Directive, Inject, InjectionToken, Optional, ViewContainerRef} from '@angular/core'; +import {Directive, InjectionToken, ViewContainerRef, inject} from '@angular/core'; /** * Injection token used to provide a `CdkTreeNode` to its outlet. @@ -23,8 +23,9 @@ export const CDK_TREE_NODE_OUTLET_NODE = new InjectionToken<{}>('CDK_TREE_NODE_O standalone: true, }) export class CdkTreeNodeOutlet { - constructor( - public viewContainer: ViewContainerRef, - @Inject(CDK_TREE_NODE_OUTLET_NODE) @Optional() public _node?: any, - ) {} + viewContainer = inject(ViewContainerRef); + _node? = inject(CDK_TREE_NODE_OUTLET_NODE, {optional: true}); + + constructor(...args: unknown[]); + constructor() {} } diff --git a/src/cdk/tree/padding.ts b/src/cdk/tree/padding.ts index 4a00ff6e98be..e96943bab840 100644 --- a/src/cdk/tree/padding.ts +++ b/src/cdk/tree/padding.ts @@ -7,7 +7,7 @@ */ import {Directionality} from '@angular/cdk/bidi'; -import {Directive, ElementRef, Input, numberAttribute, OnDestroy, Optional} from '@angular/core'; +import {Directive, ElementRef, Input, numberAttribute, OnDestroy, inject} from '@angular/core'; import {takeUntil} from 'rxjs/operators'; import {Subject} from 'rxjs'; import {CdkTree, CdkTreeNode} from './tree'; @@ -24,6 +24,11 @@ const cssUnitPattern = /([A-Za-z%]+)$/; standalone: true, }) export class CdkTreeNodePadding implements OnDestroy { + private _treeNode = inject>(CdkTreeNode); + private _tree = inject>(CdkTree); + private _element = inject>(ElementRef); + private _dir = inject(Directionality, {optional: true}); + /** Current padding value applied to the element. Used to avoid unnecessarily hitting the DOM. */ private _currentPadding: string | null; @@ -56,21 +61,16 @@ export class CdkTreeNodePadding implements OnDestroy { } _indent: number = 40; - constructor( - private _treeNode: CdkTreeNode, - private _tree: CdkTree, - private _element: ElementRef, - @Optional() private _dir: Directionality, - ) { + constructor(...args: unknown[]); + + constructor() { this._setPadding(); - if (_dir) { - _dir.change.pipe(takeUntil(this._destroyed)).subscribe(() => this._setPadding(true)); - } + this._dir?.change.pipe(takeUntil(this._destroyed)).subscribe(() => this._setPadding(true)); // In Ivy the indentation binding might be set before the tree node's data has been added, // which means that we'll miss the first render. We have to subscribe to changes in the // data to ensure that everything is up to date. - _treeNode._dataChanges.subscribe(() => this._setPadding()); + this._treeNode._dataChanges.subscribe(() => this._setPadding()); } ngOnDestroy() { diff --git a/src/cdk/tree/toggle.ts b/src/cdk/tree/toggle.ts index a10e17f80007..9f42e61374ae 100644 --- a/src/cdk/tree/toggle.ts +++ b/src/cdk/tree/toggle.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Directive, Input, booleanAttribute} from '@angular/core'; +import {Directive, Input, booleanAttribute, inject} from '@angular/core'; import {CdkTree, CdkTreeNode} from './tree'; @@ -24,14 +24,15 @@ import {CdkTree, CdkTreeNode} from './tree'; standalone: true, }) export class CdkTreeNodeToggle { + protected _tree = inject>(CdkTree); + protected _treeNode = inject>(CdkTreeNode); + /** Whether expand/collapse the node recursively. */ @Input({alias: 'cdkTreeNodeToggleRecursive', transform: booleanAttribute}) recursive: boolean = false; - constructor( - protected _tree: CdkTree, - protected _treeNode: CdkTreeNode, - ) {} + constructor(...args: unknown[]); + constructor() {} // Toggle the expanded or collapsed state of this node. // diff --git a/src/cdk/tree/tree.ts b/src/cdk/tree/tree.ts index dead7b09dbd0..fe183fa8ea66 100644 --- a/src/cdk/tree/tree.ts +++ b/src/cdk/tree/tree.ts @@ -125,6 +125,9 @@ export class CdkTree OnDestroy, OnInit { + private _differs = inject(IterableDiffers); + private _changeDetectorRef = inject(ChangeDetectorRef); + private _dir = inject(Directionality); /** Subject that emits when the component has been destroyed. */ @@ -264,10 +267,8 @@ export class CdkTree _keyManager: TreeKeyManagerStrategy>; private _viewInit = false; - constructor( - private _differs: IterableDiffers, - private _changeDetectorRef: ChangeDetectorRef, - ) {} + constructor(...args: unknown[]); + constructor() {} ngAfterContentInit() { this._initializeKeyManager(); @@ -1148,6 +1149,8 @@ export class CdkTree standalone: true, }) export class CdkTreeNode implements OnDestroy, OnInit, TreeKeyManagerItem { + protected _elementRef = inject>(ElementRef); + protected _tree = inject>(CdkTree); protected _tabindex: number | null = -1; /** @@ -1334,10 +1337,9 @@ export class CdkTreeNode implements OnDestroy, OnInit, TreeKeyManagerI private _changeDetectorRef = inject(ChangeDetectorRef); - constructor( - protected _elementRef: ElementRef, - protected _tree: CdkTree, - ) { + constructor(...args: unknown[]); + + constructor() { CdkTreeNode.mostRecentTreeNode = this as CdkTreeNode; } diff --git a/src/material/expansion/expansion-panel.ts b/src/material/expansion/expansion-panel.ts index d2a26cdbec4a..7b4c3647732b 100644 --- a/src/material/expansion/expansion-panel.ts +++ b/src/material/expansion/expansion-panel.ts @@ -160,6 +160,7 @@ export class MatExpansionPanel defaultOptions?: MatExpansionPanelDefaultOptions, ) { super(accordion, _changeDetectorRef, _uniqueSelectionDispatcher); + this._expansionDispatcher = _uniqueSelectionDispatcher; this.accordion = accordion; this._document = _document; this._animationsDisabled = _animationMode === 'NoopAnimations'; diff --git a/tools/public_api_guard/cdk/a11y.md b/tools/public_api_guard/cdk/a11y.md index dc743ad41854..22d42d45c361 100644 --- a/tools/public_api_guard/cdk/a11y.md +++ b/tools/public_api_guard/cdk/a11y.md @@ -6,7 +6,6 @@ import { AfterContentInit } from '@angular/core'; import { AfterViewInit } from '@angular/core'; -import { ContentObserver } from '@angular/cdk/observers'; import { DoCheck } from '@angular/core'; import { ElementRef } from '@angular/core'; import { EventEmitter } from '@angular/core'; @@ -18,7 +17,6 @@ import { NgZone } from '@angular/core'; import { Observable } from 'rxjs'; import { OnChanges } from '@angular/core'; import { OnDestroy } from '@angular/core'; -import { Platform } from '@angular/cdk/platform'; import { QueryList } from '@angular/core'; import { Signal } from '@angular/core'; import { SimpleChanges } from '@angular/core'; @@ -26,7 +24,7 @@ import { Subject } from 'rxjs'; // @public (undocumented) export class A11yModule { - constructor(highContrastModeDetector: HighContrastModeDetector); + constructor(); // (undocumented) static ɵfac: i0.ɵɵFactoryDeclaration; // (undocumented) @@ -46,8 +44,7 @@ export function addAriaReferencedId(el: Element, attr: `aria-${string}`, id: str // @public export class AriaDescriber implements OnDestroy { - constructor(_document: any, - _platform?: Platform | undefined); + constructor(...args: unknown[]); describe(hostElement: Element, message: string, role?: string): void; describe(hostElement: Element, message: HTMLElement): void; ngOnDestroy(): void; @@ -70,7 +67,7 @@ export const CDK_DESCRIBEDBY_ID_PREFIX = "cdk-describedby-message"; // @public export class CdkAriaLive implements OnDestroy { - constructor(_elementRef: ElementRef, _liveAnnouncer: LiveAnnouncer, _contentObserver: ContentObserver, _ngZone: NgZone); + constructor(...args: unknown[]); duration: number; // (undocumented) ngOnDestroy(): void; @@ -84,7 +81,7 @@ export class CdkAriaLive implements OnDestroy { // @public export class CdkMonitorFocus implements AfterViewInit, OnDestroy { - constructor(_elementRef: ElementRef, _focusMonitor: FocusMonitor); + constructor(...args: unknown[]); // (undocumented) readonly cdkFocusChange: EventEmitter; // (undocumented) @@ -101,8 +98,7 @@ export class CdkMonitorFocus implements AfterViewInit, OnDestroy { // @public export class CdkTrapFocus implements OnDestroy, AfterContentInit, OnChanges, DoCheck { - constructor(_elementRef: ElementRef, _focusTrapFactory: FocusTrapFactory, - _document: any); + constructor(...args: unknown[]); autoCapture: boolean; get enabled(): boolean; set enabled(value: boolean); @@ -142,12 +138,12 @@ export interface ConfigurableFocusTrapConfig { // @public export class ConfigurableFocusTrapFactory { - constructor(_checker: InteractivityChecker, _ngZone: NgZone, _focusTrapManager: FocusTrapManager, _document: any, _inertStrategy?: FocusTrapInertStrategy); + constructor(...args: unknown[]); create(element: HTMLElement, config?: ConfigurableFocusTrapConfig): ConfigurableFocusTrap; // @deprecated (undocumented) create(element: HTMLElement, deferCaptureElements: boolean): ConfigurableFocusTrap; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; // (undocumented) static ɵprov: i0.ɵɵInjectableDeclaration; } @@ -178,9 +174,8 @@ export class FocusKeyManager extends ListKeyManager { // @public export class FocusMonitor implements OnDestroy { - constructor(_ngZone: NgZone, _platform: Platform, _inputModalityDetector: InputModalityDetector, - document: any | null, options: FocusMonitorOptions | null); - protected _document?: Document; + constructor(...args: unknown[]); + protected _document?: Document | null | undefined; focusVia(element: HTMLElement, origin: FocusOrigin, options?: FocusOptions_2): void; focusVia(element: ElementRef, origin: FocusOrigin, options?: FocusOptions_2): void; monitor(element: HTMLElement, checkChildren?: boolean): Observable; @@ -191,7 +186,7 @@ export class FocusMonitor implements OnDestroy { stopMonitoring(element: HTMLElement): void; stopMonitoring(element: ElementRef): void; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; // (undocumented) static ɵprov: i0.ɵɵInjectableDeclaration; } @@ -250,7 +245,7 @@ export class FocusTrap { // @public export class FocusTrapFactory { - constructor(_checker: InteractivityChecker, _ngZone: NgZone, _document: any); + constructor(...args: unknown[]); create(element: HTMLElement, deferCaptureElements?: boolean): FocusTrap; // (undocumented) static ɵfac: i0.ɵɵFactoryDeclaration; @@ -279,7 +274,7 @@ export enum HighContrastMode { // @public export class HighContrastModeDetector implements OnDestroy { - constructor(_platform: Platform, document: any); + constructor(...args: unknown[]); _applyBodyHighContrastModeCssClasses(): void; getHighContrastMode(): HighContrastMode; // (undocumented) @@ -307,7 +302,7 @@ export type InputModality = 'keyboard' | 'mouse' | 'touch' | null; // @public export class InputModalityDetector implements OnDestroy { - constructor(_platform: Platform, ngZone: NgZone, document: Document, options?: InputModalityDetectorOptions); + constructor(...args: unknown[]); readonly modalityChanged: Observable; readonly modalityDetected: Observable; get mostRecentModality(): InputModality; @@ -315,7 +310,7 @@ export class InputModalityDetector implements OnDestroy { // (undocumented) ngOnDestroy(): void; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; // (undocumented) static ɵprov: i0.ɵɵInjectableDeclaration; } @@ -327,7 +322,7 @@ export interface InputModalityDetectorOptions { // @public export class InteractivityChecker { - constructor(_platform: Platform); + constructor(...args: unknown[]); isDisabled(element: HTMLElement): boolean; isFocusable(element: HTMLElement, config?: IsFocusableConfig): boolean; isTabbable(element: HTMLElement): boolean; @@ -399,7 +394,7 @@ export function LIVE_ANNOUNCER_ELEMENT_TOKEN_FACTORY(): null; // @public (undocumented) export class LiveAnnouncer implements OnDestroy { - constructor(elementToken: any, _ngZone: NgZone, _document: any, _defaultOptions?: LiveAnnouncerDefaultOptions | undefined); + constructor(...args: unknown[]); announce(message: string): Promise; announce(message: string, politeness?: AriaLivePoliteness): Promise; announce(message: string, duration?: number): Promise; @@ -408,7 +403,7 @@ export class LiveAnnouncer implements OnDestroy { // (undocumented) ngOnDestroy(): void; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; // (undocumented) static ɵprov: i0.ɵɵInjectableDeclaration; } diff --git a/tools/public_api_guard/cdk/accordion.md b/tools/public_api_guard/cdk/accordion.md index 716cac8f1b5a..272ecd145787 100644 --- a/tools/public_api_guard/cdk/accordion.md +++ b/tools/public_api_guard/cdk/accordion.md @@ -4,12 +4,12 @@ ```ts -import { ChangeDetectorRef } from '@angular/core'; import { EventEmitter } from '@angular/core'; import * as i0 from '@angular/core'; import { InjectionToken } from '@angular/core'; import { OnChanges } from '@angular/core'; import { OnDestroy } from '@angular/core'; +import { OnInit } from '@angular/core'; import { SimpleChanges } from '@angular/core'; import { Subject } from 'rxjs'; import { UniqueSelectionDispatcher } from '@angular/cdk/collections'; @@ -38,8 +38,8 @@ export class CdkAccordion implements OnDestroy, OnChanges { } // @public -export class CdkAccordionItem implements OnDestroy { - constructor(accordion: CdkAccordion, _changeDetectorRef: ChangeDetectorRef, _expansionDispatcher: UniqueSelectionDispatcher); +export class CdkAccordionItem implements OnInit, OnDestroy { + constructor(...args: unknown[]); // (undocumented) accordion: CdkAccordion; close(): void; @@ -57,13 +57,15 @@ export class CdkAccordionItem implements OnDestroy { // (undocumented) static ngAcceptInputType_expanded: unknown; ngOnDestroy(): void; + // (undocumented) + ngOnInit(): void; open(): void; readonly opened: EventEmitter; toggle(): void; // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public (undocumented) diff --git a/tools/public_api_guard/cdk/bidi.md b/tools/public_api_guard/cdk/bidi.md index b10b1c2ec933..3f7fc30f7e8c 100644 --- a/tools/public_api_guard/cdk/bidi.md +++ b/tools/public_api_guard/cdk/bidi.md @@ -44,13 +44,13 @@ export type Direction = 'ltr' | 'rtl'; // @public export class Directionality implements OnDestroy { - constructor(_document?: any); + constructor(...args: unknown[]); readonly change: EventEmitter; // (undocumented) ngOnDestroy(): void; readonly value: Direction; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; // (undocumented) static ɵprov: i0.ɵɵInjectableDeclaration; } diff --git a/tools/public_api_guard/cdk/clipboard.md b/tools/public_api_guard/cdk/clipboard.md index f44beb8403b8..406d9927a1ae 100644 --- a/tools/public_api_guard/cdk/clipboard.md +++ b/tools/public_api_guard/cdk/clipboard.md @@ -7,7 +7,6 @@ import { EventEmitter } from '@angular/core'; import * as i0 from '@angular/core'; import { InjectionToken } from '@angular/core'; -import { NgZone } from '@angular/core'; import { OnDestroy } from '@angular/core'; // @public @@ -15,7 +14,7 @@ export const CDK_COPY_TO_CLIPBOARD_CONFIG: InjectionToken; copy(attempts?: number): void; @@ -25,7 +24,7 @@ export class CdkCopyToClipboard implements OnDestroy { // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public @@ -35,7 +34,7 @@ export interface CdkCopyToClipboardConfig { // @public class Clipboard_2 { - constructor(document: any); + constructor(...args: unknown[]); beginCopy(text: string): PendingCopy; copy(text: string): boolean; // (undocumented) diff --git a/tools/public_api_guard/cdk/dialog.md b/tools/public_api_guard/cdk/dialog.md index 67d084dd95c9..f978cf8aba8e 100644 --- a/tools/public_api_guard/cdk/dialog.md +++ b/tools/public_api_guard/cdk/dialog.md @@ -15,7 +15,6 @@ import { Direction } from '@angular/cdk/bidi'; import { DomPortal } from '@angular/cdk/portal'; import { ElementRef } from '@angular/core'; import { EmbeddedViewRef } from '@angular/core'; -import { FocusMonitor } from '@angular/cdk/a11y'; import { FocusOrigin } from '@angular/cdk/a11y'; import { FocusTrapFactory } from '@angular/cdk/a11y'; import * as i0 from '@angular/core'; @@ -24,12 +23,10 @@ import * as i2 from '@angular/cdk/portal'; import * as i3 from '@angular/cdk/a11y'; import { InjectionToken } from '@angular/core'; import { Injector } from '@angular/core'; -import { InteractivityChecker } from '@angular/cdk/a11y'; import { NgZone } from '@angular/core'; import { Observable } from 'rxjs'; import { OnDestroy } from '@angular/core'; import { Overlay } from '@angular/cdk/overlay'; -import { OverlayContainer } from '@angular/cdk/overlay'; import { OverlayRef } from '@angular/cdk/overlay'; import { PositionStrategy } from '@angular/cdk/overlay'; import { ScrollStrategy } from '@angular/cdk/overlay'; @@ -45,7 +42,7 @@ export type AutoFocusTarget = 'dialog' | 'first-tabbable' | 'first-heading'; // @public export class CdkDialogContainer extends BasePortalOutlet implements OnDestroy { - constructor(_elementRef: ElementRef, _focusTrapFactory: FocusTrapFactory, _document: any, _config: C, _interactivityChecker: InteractivityChecker, _ngZone: NgZone, _overlayRef: OverlayRef, _focusMonitor?: FocusMonitor | undefined); + constructor(...args: unknown[]); // (undocumented) _addAriaLabelledBy(id: string): void; _ariaLabelledByQueue: string[]; @@ -64,7 +61,7 @@ export class CdkDialogContainer extends B // (undocumented) protected _document: Document; // (undocumented) - protected _elementRef: ElementRef; + protected _elementRef: ElementRef; // (undocumented) protected _focusTrapFactory: FocusTrapFactory; // (undocumented) @@ -79,7 +76,7 @@ export class CdkDialogContainer extends B // (undocumented) static ɵcmp: i0.ɵɵComponentDeclaration, "cdk-dialog-container", never, {}, {}, never, never, true, never>; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration, [null, null, { optional: true; }, null, null, null, null, null]>; + static ɵfac: i0.ɵɵFactoryDeclaration, never>; } // @public @@ -87,7 +84,7 @@ export const DEFAULT_DIALOG_CONFIG: InjectionToken; get afterOpened(): Subject>; closeAll(): void; @@ -100,7 +97,7 @@ export class Dialog implements OnDestroy { open(componentOrTemplateRef: ComponentType | TemplateRef, config?: DialogConfig>): DialogRef; get openDialogs(): readonly DialogRef[]; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; // (undocumented) static ɵprov: i0.ɵɵInjectableDeclaration; } diff --git a/tools/public_api_guard/cdk/drag-drop.md b/tools/public_api_guard/cdk/drag-drop.md index eac49304fa19..bb39566f6fdc 100644 --- a/tools/public_api_guard/cdk/drag-drop.md +++ b/tools/public_api_guard/cdk/drag-drop.md @@ -5,9 +5,7 @@ ```ts import { AfterViewInit } from '@angular/core'; -import { ChangeDetectorRef } from '@angular/core'; import { Direction } from '@angular/cdk/bidi'; -import { Directionality } from '@angular/cdk/bidi'; import { ElementRef } from '@angular/core'; import { EventEmitter } from '@angular/core'; import * as i0 from '@angular/core'; @@ -18,7 +16,6 @@ import { NumberInput } from '@angular/cdk/coercion'; import { Observable } from 'rxjs'; import { OnChanges } from '@angular/core'; import { OnDestroy } from '@angular/core'; -import { ScrollDispatcher } from '@angular/cdk/scrolling'; import { SimpleChanges } from '@angular/core'; import { Subject } from 'rxjs'; import { TemplateRef } from '@angular/core'; @@ -48,10 +45,7 @@ export const CDK_DROP_LIST_GROUP: InjectionToken>; // @public export class CdkDrag implements AfterViewInit, OnChanges, OnDestroy { - constructor( - element: ElementRef, - dropContainer: CdkDropList, - _document: any, _ngZone: NgZone, _viewContainerRef: ViewContainerRef, config: DragDropConfig, _dir: Directionality, dragDrop: DragDrop, _changeDetectorRef: ChangeDetectorRef, _selfHandle?: CdkDragHandle | undefined, _parentDrag?: CdkDrag | undefined); + constructor(...args: unknown[]); // (undocumented) _addHandle(handle: CdkDragHandle): void; boundaryElement: string | ElementRef | HTMLElement; @@ -61,8 +55,10 @@ export class CdkDrag implements AfterViewInit, OnChanges, OnDestroy { set disabled(value: boolean); _dragRef: DragRef>; dragStartDelay: DragStartDelay; - dropContainer: CdkDropList; + // (undocumented) + dropContainer: CdkDropList; readonly dropped: EventEmitter>; + // (undocumented) element: ElementRef; readonly ended: EventEmitter; readonly entered: EventEmitter>; @@ -104,7 +100,7 @@ export class CdkDrag implements AfterViewInit, OnChanges, OnDestroy { // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration, "[cdkDrag]", ["cdkDrag"], { "data": { "alias": "cdkDragData"; "required": false; }; "lockAxis": { "alias": "cdkDragLockAxis"; "required": false; }; "rootElementSelector": { "alias": "cdkDragRootElement"; "required": false; }; "boundaryElement": { "alias": "cdkDragBoundary"; "required": false; }; "dragStartDelay": { "alias": "cdkDragStartDelay"; "required": false; }; "freeDragPosition": { "alias": "cdkDragFreeDragPosition"; "required": false; }; "disabled": { "alias": "cdkDragDisabled"; "required": false; }; "constrainPosition": { "alias": "cdkDragConstrainPosition"; "required": false; }; "previewClass": { "alias": "cdkDragPreviewClass"; "required": false; }; "previewContainer": { "alias": "cdkDragPreviewContainer"; "required": false; }; "scale": { "alias": "cdkDragScale"; "required": false; }; }, { "started": "cdkDragStarted"; "released": "cdkDragReleased"; "ended": "cdkDragEnded"; "entered": "cdkDragEntered"; "exited": "cdkDragExited"; "dropped": "cdkDragDropped"; "moved": "cdkDragMoved"; }, never, never, true, never>; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration, [null, { optional: true; skipSelf: true; }, null, null, null, { optional: true; }, { optional: true; }, null, null, { optional: true; self: true; }, { optional: true; skipSelf: true; }]>; + static ɵfac: i0.ɵɵFactoryDeclaration, never>; } // @public @@ -155,7 +151,7 @@ export interface CdkDragExit { // @public export class CdkDragHandle implements OnDestroy { - constructor(element: ElementRef, _parentDrag?: CdkDrag | undefined); + constructor(...args: unknown[]); get disabled(): boolean; set disabled(value: boolean); // (undocumented) @@ -168,7 +164,7 @@ export class CdkDragHandle implements OnDestroy { // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public @@ -191,7 +187,7 @@ export interface CdkDragMove { // @public export class CdkDragPlaceholder implements OnDestroy { - constructor(templateRef: TemplateRef); + constructor(...args: unknown[]); data: T; // (undocumented) ngOnDestroy(): void; @@ -205,7 +201,7 @@ export class CdkDragPlaceholder implements OnDestroy { // @public export class CdkDragPreview implements OnDestroy { - constructor(templateRef: TemplateRef); + constructor(...args: unknown[]); data: T; matchSize: boolean; // (undocumented) @@ -242,8 +238,7 @@ export interface CdkDragStart { // @public export class CdkDropList implements OnDestroy { - constructor( - element: ElementRef, dragDrop: DragDrop, _changeDetectorRef: ChangeDetectorRef, _scrollDispatcher: ScrollDispatcher, _dir?: Directionality | undefined, _group?: CdkDropListGroup | undefined, config?: DragDropConfig); + constructor(...args: unknown[]); addItem(item: CdkDrag): void; autoScrollDisabled: boolean; autoScrollStep: NumberInput; @@ -253,6 +248,7 @@ export class CdkDropList implements OnDestroy { set disabled(value: boolean); _dropListRef: DropListRef>; readonly dropped: EventEmitter>; + // (undocumented) element: ElementRef; elementContainerSelector: string | null; readonly entered: EventEmitter>; @@ -277,7 +273,7 @@ export class CdkDropList implements OnDestroy { // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration, "[cdkDropList], cdk-drop-list", ["cdkDropList"], { "connectedTo": { "alias": "cdkDropListConnectedTo"; "required": false; }; "data": { "alias": "cdkDropListData"; "required": false; }; "orientation": { "alias": "cdkDropListOrientation"; "required": false; }; "id": { "alias": "id"; "required": false; }; "lockAxis": { "alias": "cdkDropListLockAxis"; "required": false; }; "disabled": { "alias": "cdkDropListDisabled"; "required": false; }; "sortingDisabled": { "alias": "cdkDropListSortingDisabled"; "required": false; }; "enterPredicate": { "alias": "cdkDropListEnterPredicate"; "required": false; }; "sortPredicate": { "alias": "cdkDropListSortPredicate"; "required": false; }; "autoScrollDisabled": { "alias": "cdkDropListAutoScrollDisabled"; "required": false; }; "autoScrollStep": { "alias": "cdkDropListAutoScrollStep"; "required": false; }; "elementContainerSelector": { "alias": "cdkDropListElementContainer"; "required": false; }; }, { "dropped": "cdkDropListDropped"; "entered": "cdkDropListEntered"; "exited": "cdkDropListExited"; "sorted": "cdkDropListSorted"; }, never, never, true, never>; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration, [null, null, null, null, { optional: true; }, { optional: true; skipSelf: true; }, { optional: true; }]>; + static ɵfac: i0.ɵɵFactoryDeclaration, never>; } // @public @@ -305,7 +301,7 @@ export type DragConstrainPosition = (point: Point, dragRef: DragRef) => Point; // @public export class DragDrop { - constructor(_document: any, _ngZone: NgZone, _viewportRuler: ViewportRuler, _dragDropRegistry: DragDropRegistry); + constructor(...args: unknown[]); createDrag(element: ElementRef | HTMLElement, config?: DragRefConfig): DragRef; createDropList(element: ElementRef | HTMLElement): DropListRef; // (undocumented) @@ -354,7 +350,7 @@ export class DragDropModule { // @public export class DragDropRegistry<_ = unknown, __ = unknown> implements OnDestroy { - constructor(_ngZone: NgZone, _document: any); + constructor(...args: unknown[]); isDragging(drag: DragRef): boolean; // (undocumented) ngOnDestroy(): void; diff --git a/tools/public_api_guard/cdk/layout.md b/tools/public_api_guard/cdk/layout.md index 8ff9ecd26d88..7b6a42cfdefb 100644 --- a/tools/public_api_guard/cdk/layout.md +++ b/tools/public_api_guard/cdk/layout.md @@ -5,14 +5,12 @@ ```ts import * as i0 from '@angular/core'; -import { NgZone } from '@angular/core'; import { Observable } from 'rxjs'; import { OnDestroy } from '@angular/core'; -import { Platform } from '@angular/cdk/platform'; // @public export class BreakpointObserver implements OnDestroy { - constructor(_mediaMatcher: MediaMatcher, _zone: NgZone); + constructor(...args: unknown[]); isMatched(value: string | readonly string[]): boolean; ngOnDestroy(): void; observe(value: string | readonly string[]): Observable; @@ -60,10 +58,10 @@ export class LayoutModule { // @public export class MediaMatcher { - constructor(_platform: Platform, _nonce?: (string | null) | undefined); + constructor(...args: unknown[]); matchMedia(query: string): MediaQueryList; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; // (undocumented) static ɵprov: i0.ɵɵInjectableDeclaration; } diff --git a/tools/public_api_guard/cdk/observers.md b/tools/public_api_guard/cdk/observers.md index e155cb71b011..f4c8684f1feb 100644 --- a/tools/public_api_guard/cdk/observers.md +++ b/tools/public_api_guard/cdk/observers.md @@ -14,7 +14,7 @@ import { OnDestroy } from '@angular/core'; // @public export class CdkObserveContent implements AfterContentInit, OnDestroy { - constructor(_contentObserver: ContentObserver, _elementRef: ElementRef); + constructor(...args: unknown[]); get debounce(): number; set debounce(value: NumberInput); get disabled(): boolean; @@ -34,7 +34,7 @@ export class CdkObserveContent implements AfterContentInit, OnDestroy { // @public export class ContentObserver implements OnDestroy { - constructor(_mutationObserverFactory: MutationObserverFactory); + constructor(...args: unknown[]); // (undocumented) ngOnDestroy(): void; observe(element: Element): Observable; diff --git a/tools/public_api_guard/cdk/overlay.md b/tools/public_api_guard/cdk/overlay.md index 593e40aa004d..4170e1a05877 100644 --- a/tools/public_api_guard/cdk/overlay.md +++ b/tools/public_api_guard/cdk/overlay.md @@ -6,7 +6,6 @@ import { _CdkPrivateStyleLoader } from '@angular/cdk/private'; import { CdkScrollable } from '@angular/cdk/scrolling'; -import { ComponentFactoryResolver } from '@angular/core'; import { ComponentPortal } from '@angular/cdk/portal'; import { ComponentRef } from '@angular/core'; import { ComponentType } from '@angular/cdk/portal'; @@ -21,7 +20,6 @@ import * as i1 from '@angular/cdk/bidi'; import * as i2 from '@angular/cdk/portal'; import * as i3 from '@angular/cdk/scrolling'; import { InjectionToken } from '@angular/core'; -import { Injector } from '@angular/core'; import { Location as Location_2 } from '@angular/common'; import { NgZone } from '@angular/core'; import { Observable } from 'rxjs'; @@ -33,8 +31,6 @@ import { ScrollDispatcher } from '@angular/cdk/scrolling'; import { SimpleChanges } from '@angular/core'; import { Subject } from 'rxjs'; import { TemplatePortal } from '@angular/cdk/portal'; -import { TemplateRef } from '@angular/core'; -import { ViewContainerRef } from '@angular/core'; import { ViewportRuler } from '@angular/cdk/scrolling'; // @public @@ -47,7 +43,7 @@ export class BlockScrollStrategy implements ScrollStrategy { // @public export class CdkConnectedOverlay implements OnDestroy, OnChanges { - constructor(_overlay: Overlay, templateRef: TemplateRef, viewContainerRef: ViewContainerRef, scrollStrategyFactory: any, _dir: Directionality); + constructor(...args: unknown[]); readonly attach: EventEmitter; backdropClass: string | string[]; readonly backdropClick: EventEmitter; @@ -100,14 +96,14 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges { // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public export class CdkOverlayOrigin { - constructor( - elementRef: ElementRef); - elementRef: ElementRef; + constructor(...args: unknown[]); + // (undocumented) + elementRef: ElementRef; // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) @@ -206,7 +202,7 @@ export type FlexibleConnectedPositionStrategyOrigin = ElementRef | Element | (Po // @public export class FullscreenOverlayContainer extends OverlayContainer implements OnDestroy { - constructor(_document: any, platform: Platform); + constructor(...args: unknown[]); // (undocumented) protected _createContainer(): void; getFullscreenElement(): Element; @@ -258,13 +254,13 @@ export interface OriginConnectionPosition { // @public export class Overlay { - constructor( - scrollStrategies: ScrollStrategyOptions, _overlayContainer: OverlayContainer, _componentFactoryResolver: ComponentFactoryResolver, _positionBuilder: OverlayPositionBuilder, _keyboardDispatcher: OverlayKeyboardDispatcher, _injector: Injector, _ngZone: NgZone, _document: any, _directionality: Directionality, _location: Location_2, _outsideClickDispatcher: OverlayOutsideClickDispatcher, _animationsModuleType?: string | undefined); + constructor(...args: unknown[]); create(config?: OverlayConfig): OverlayRef; position(): OverlayPositionBuilder; + // (undocumented) scrollStrategies: ScrollStrategyOptions; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; // (undocumented) static ɵprov: i0.ɵɵInjectableDeclaration; } @@ -297,7 +293,7 @@ export interface OverlayConnectionPosition { // @public export class OverlayContainer implements OnDestroy { - constructor(document: any, _platform: Platform); + constructor(...args: unknown[]); // (undocumented) protected _containerElement: HTMLElement; protected _createContainer(): void; @@ -319,12 +315,10 @@ export class OverlayContainer implements OnDestroy { // @public export class OverlayKeyboardDispatcher extends BaseOverlayDispatcher { - constructor(document: any, - _ngZone?: NgZone | undefined); add(overlayRef: OverlayRef): void; protected detach(): void; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; // (undocumented) static ɵprov: i0.ɵɵInjectableDeclaration; } @@ -341,19 +335,17 @@ export class OverlayModule { // @public export class OverlayOutsideClickDispatcher extends BaseOverlayDispatcher { - constructor(document: any, _platform: Platform, - _ngZone?: NgZone | undefined); add(overlayRef: OverlayRef): void; protected detach(): void; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; // (undocumented) static ɵprov: i0.ɵɵInjectableDeclaration; } // @public export class OverlayPositionBuilder { - constructor(_viewportRuler: ViewportRuler, _document: any, _platform: Platform, _overlayContainer: OverlayContainer); + constructor(...args: unknown[]); flexibleConnectedTo(origin: FlexibleConnectedPositionStrategyOrigin): FlexibleConnectedPositionStrategy; global(): GlobalPositionStrategy; // (undocumented) @@ -460,7 +452,7 @@ export interface ScrollStrategy { // @public export class ScrollStrategyOptions { - constructor(_scrollDispatcher: ScrollDispatcher, _viewportRuler: ViewportRuler, _ngZone: NgZone, document: any); + constructor(...args: unknown[]); block: () => BlockScrollStrategy; close: (config?: CloseScrollStrategyConfig) => CloseScrollStrategy; noop: () => NoopScrollStrategy; diff --git a/tools/public_api_guard/cdk/portal.md b/tools/public_api_guard/cdk/portal.md index 4dfe85909b33..c0bc7ad875a5 100644 --- a/tools/public_api_guard/cdk/portal.md +++ b/tools/public_api_guard/cdk/portal.md @@ -44,7 +44,7 @@ export abstract class BasePortalOutlet implements PortalOutlet { // @public export class CdkPortal extends TemplatePortal { - constructor(templateRef: TemplateRef, viewContainerRef: ViewContainerRef); + constructor(...args: unknown[]); // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) @@ -53,8 +53,7 @@ export class CdkPortal extends TemplatePortal { // @public export class CdkPortalOutlet extends BasePortalOutlet implements OnInit, OnDestroy { - constructor(_componentFactoryResolver: ComponentFactoryResolver, _viewContainerRef: ViewContainerRef, - _document?: any); + constructor(...args: unknown[]); attachComponentPortal(portal: ComponentPortal): ComponentRef; // @deprecated attachDomPortal: (portal: DomPortal) => void; diff --git a/tools/public_api_guard/cdk/scrolling.md b/tools/public_api_guard/cdk/scrolling.md index 014312a5189b..9e7cf19bab61 100644 --- a/tools/public_api_guard/cdk/scrolling.md +++ b/tools/public_api_guard/cdk/scrolling.md @@ -4,7 +4,6 @@ ```ts -import { ChangeDetectorRef } from '@angular/core'; import { CollectionViewer } from '@angular/cdk/collections'; import { DataSource } from '@angular/cdk/collections'; import { Directionality } from '@angular/cdk/bidi'; @@ -13,7 +12,6 @@ import { ElementRef } from '@angular/core'; import * as i0 from '@angular/core'; import * as i2 from '@angular/cdk/bidi'; import { InjectionToken } from '@angular/core'; -import { IterableDiffers } from '@angular/core'; import { ListRange } from '@angular/cdk/collections'; import { NgIterable } from '@angular/core'; import { NgZone } from '@angular/core'; @@ -22,13 +20,10 @@ import { Observable } from 'rxjs'; import { OnChanges } from '@angular/core'; import { OnDestroy } from '@angular/core'; import { OnInit } from '@angular/core'; -import { Platform } from '@angular/cdk/platform'; -import { _RecycleViewRepeaterStrategy } from '@angular/cdk/collections'; import { Subject } from 'rxjs'; import { Subscription } from 'rxjs'; import { TemplateRef } from '@angular/core'; import { TrackByFunction } from '@angular/core'; -import { ViewContainerRef } from '@angular/core'; // @public (undocumented) export type _Bottom = { @@ -60,11 +55,11 @@ export class CdkFixedSizeVirtualScroll implements OnChanges { // @public export class CdkScrollable implements OnInit, OnDestroy { - constructor(elementRef: ElementRef, scrollDispatcher: ScrollDispatcher, ngZone: NgZone, dir?: Directionality | undefined); + constructor(...args: unknown[]); // (undocumented) protected readonly _destroyed: Subject; // (undocumented) - protected dir?: Directionality | undefined; + protected dir?: Directionality | null | undefined; // (undocumented) protected elementRef: ElementRef; elementScrolled(): Observable; @@ -84,7 +79,7 @@ export class CdkScrollable implements OnInit, OnDestroy { // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public (undocumented) @@ -99,12 +94,7 @@ export class CdkScrollableModule { // @public export class CdkVirtualForOf implements CdkVirtualScrollRepeater, CollectionViewer, DoCheck, OnDestroy { - constructor( - _viewContainerRef: ViewContainerRef, - _template: TemplateRef>, - _differs: IterableDiffers, - _viewRepeater: _RecycleViewRepeaterStrategy>, - _viewport: CdkVirtualScrollViewport, ngZone: NgZone); + constructor(...args: unknown[]); get cdkVirtualForOf(): DataSource | Observable | NgIterable | null | undefined; set cdkVirtualForOf(value: DataSource | Observable | NgIterable | null | undefined); // (undocumented) @@ -126,7 +116,7 @@ export class CdkVirtualForOf implements CdkVirtualScrollRepeater, Collecti // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration, "[cdkVirtualFor][cdkVirtualForOf]", never, { "cdkVirtualForOf": { "alias": "cdkVirtualForOf"; "required": false; }; "cdkVirtualForTrackBy": { "alias": "cdkVirtualForTrackBy"; "required": false; }; "cdkVirtualForTemplate": { "alias": "cdkVirtualForTemplate"; "required": false; }; "cdkVirtualForTemplateCacheSize": { "alias": "cdkVirtualForTemplateCacheSize"; "required": false; }; }, {}, never, never, true, never>; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration, [null, null, null, null, { skipSelf: true; }, null]>; + static ɵfac: i0.ɵɵFactoryDeclaration, never>; } // @public @@ -143,29 +133,29 @@ export type CdkVirtualForOfContext = { // @public export abstract class CdkVirtualScrollable extends CdkScrollable { - constructor(elementRef: ElementRef, scrollDispatcher: ScrollDispatcher, ngZone: NgZone, dir?: Directionality); + constructor(...args: unknown[]); abstract measureBoundingClientRectWithScrollOffset(from: 'left' | 'top' | 'right' | 'bottom'): number; measureViewportSize(orientation: 'horizontal' | 'vertical'): number; // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public export class CdkVirtualScrollableElement extends CdkVirtualScrollable { - constructor(elementRef: ElementRef, scrollDispatcher: ScrollDispatcher, ngZone: NgZone, dir: Directionality); + constructor(...args: unknown[]); // (undocumented) measureBoundingClientRectWithScrollOffset(from: 'left' | 'top' | 'right' | 'bottom'): number; // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public export class CdkVirtualScrollableWindow extends CdkVirtualScrollable { - constructor(scrollDispatcher: ScrollDispatcher, ngZone: NgZone, dir: Directionality); + constructor(...args: unknown[]); // (undocumented) protected _elementScrolled: Observable; // (undocumented) @@ -173,7 +163,7 @@ export class CdkVirtualScrollableWindow extends CdkVirtualScrollable { // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public @@ -186,7 +176,7 @@ export interface CdkVirtualScrollRepeater { // @public export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements OnInit, OnDestroy { - constructor(elementRef: ElementRef, _changeDetectorRef: ChangeDetectorRef, ngZone: NgZone, _scrollStrategy: VirtualScrollStrategy, dir: Directionality, scrollDispatcher: ScrollDispatcher, viewportRuler: ViewportRuler, scrollable: CdkVirtualScrollable); + constructor(...args: unknown[]); appendOnly: boolean; attach(forOf: CdkVirtualScrollRepeater): void; checkViewportSize(): void; @@ -226,7 +216,7 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On // (undocumented) static ɵcmp: i0.ɵɵComponentDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public @@ -272,7 +262,7 @@ export type _Right = { // @public export class ScrollDispatcher implements OnDestroy { - constructor(_ngZone: NgZone, _platform: Platform, document: any); + constructor(...args: unknown[]); ancestorScrolled(elementOrElementRef: ElementRef | HTMLElement, auditTimeInMs?: number): Observable; deregister(scrollable: CdkScrollable): void; protected _document: Document; @@ -284,7 +274,7 @@ export class ScrollDispatcher implements OnDestroy { scrollContainers: Map; scrolled(auditTimeInMs?: number): Observable; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; // (undocumented) static ɵprov: i0.ɵɵInjectableDeclaration; } @@ -311,7 +301,7 @@ export type _Top = { // @public export class ViewportRuler implements OnDestroy { - constructor(_platform: Platform, ngZone: NgZone, document: any); + constructor(...args: unknown[]); change(throttleTime?: number): Observable; protected _document: Document; getViewportRect(): { @@ -330,7 +320,7 @@ export class ViewportRuler implements OnDestroy { // (undocumented) ngOnDestroy(): void; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; // (undocumented) static ɵprov: i0.ɵɵInjectableDeclaration; } diff --git a/tools/public_api_guard/cdk/stepper.md b/tools/public_api_guard/cdk/stepper.md index 170e87b77fa1..de11cf1d9db7 100644 --- a/tools/public_api_guard/cdk/stepper.md +++ b/tools/public_api_guard/cdk/stepper.md @@ -6,8 +6,6 @@ import { AfterContentInit } from '@angular/core'; import { AfterViewInit } from '@angular/core'; -import { ChangeDetectorRef } from '@angular/core'; -import { Directionality } from '@angular/cdk/bidi'; import { ElementRef } from '@angular/core'; import { EventEmitter } from '@angular/core'; import { FocusableOption } from '@angular/cdk/a11y'; @@ -23,7 +21,7 @@ import { TemplateRef } from '@angular/core'; // @public (undocumented) export class CdkStep implements OnChanges { - constructor(_stepper: CdkStepper, stepperOptions?: StepperOptions); + constructor(...args: unknown[]); ariaLabel: string; ariaLabelledby: string; get completed(): boolean; @@ -64,12 +62,12 @@ export class CdkStep implements OnChanges { // (undocumented) static ɵcmp: i0.ɵɵComponentDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public (undocumented) export class CdkStepHeader implements FocusableOption { - constructor(_elementRef: ElementRef); + constructor(...args: unknown[]); // (undocumented) _elementRef: ElementRef; focus(): void; @@ -81,7 +79,7 @@ export class CdkStepHeader implements FocusableOption { // @public (undocumented) export class CdkStepLabel { - constructor(template: TemplateRef); + constructor(...args: unknown[]); // (undocumented) template: TemplateRef; // (undocumented) @@ -92,7 +90,7 @@ export class CdkStepLabel { // @public (undocumented) export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy { - constructor(_dir: Directionality, _changeDetectorRef: ChangeDetectorRef, _elementRef: ElementRef); + constructor(...args: unknown[]); protected readonly _destroyed: Subject; _getAnimationDirection(index: number): StepContentPositionState; _getFocusIndex(): number | null; @@ -131,7 +129,7 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy { // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public (undocumented) @@ -146,7 +144,7 @@ export class CdkStepperModule { // @public export class CdkStepperNext { - constructor(_stepper: CdkStepper); + constructor(...args: unknown[]); // (undocumented) _stepper: CdkStepper; type: string; @@ -158,7 +156,7 @@ export class CdkStepperNext { // @public export class CdkStepperPrevious { - constructor(_stepper: CdkStepper); + constructor(...args: unknown[]); // (undocumented) _stepper: CdkStepper; type: string; diff --git a/tools/public_api_guard/cdk/table.md b/tools/public_api_guard/cdk/table.md index 3587400512f0..ed881068621e 100644 --- a/tools/public_api_guard/cdk/table.md +++ b/tools/public_api_guard/cdk/table.md @@ -20,18 +20,15 @@ import { InjectionToken } from '@angular/core'; import { IterableChanges } from '@angular/core'; import { IterableDiffer } from '@angular/core'; import { IterableDiffers } from '@angular/core'; -import { NgZone } from '@angular/core'; import { Observable } from 'rxjs'; import { OnChanges } from '@angular/core'; import { OnDestroy } from '@angular/core'; import { OnInit } from '@angular/core'; -import { Platform } from '@angular/cdk/platform'; import { QueryList } from '@angular/core'; import { SimpleChanges } from '@angular/core'; import { TemplateRef } from '@angular/core'; import { TrackByFunction } from '@angular/core'; import { ViewContainerRef } from '@angular/core'; -import { ViewportRuler } from '@angular/cdk/scrolling'; import { _ViewRepeater } from '@angular/cdk/collections'; // @public @@ -41,8 +38,7 @@ export class BaseCdkCell { // @public export abstract class BaseRowDef implements OnChanges { - constructor( - template: TemplateRef, _differs: IterableDiffers); + constructor(...args: unknown[]); columns: Iterable; protected _columnsDiffer: IterableDiffer; // (undocumented) @@ -51,6 +47,7 @@ export abstract class BaseRowDef implements OnChanges { getColumnsDiff(): IterableChanges | null; // (undocumented) ngOnChanges(changes: SimpleChanges): void; + // (undocumented) template: TemplateRef; // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; @@ -79,7 +76,7 @@ export const CDK_TABLE_TEMPLATE = "\n \n ; // (undocumented) @@ -88,8 +85,7 @@ export class CdkCell extends BaseCdkCell { // @public export class CdkCellDef implements CellDef { - constructor(template: TemplateRef); - // (undocumented) + constructor(...args: unknown[]); template: TemplateRef; // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; @@ -99,7 +95,7 @@ export class CdkCellDef implements CellDef { // @public export class CdkCellOutlet implements OnDestroy { - constructor(_viewContainer: ViewContainerRef); + constructor(...args: unknown[]); cells: CdkCellDef[]; context: any; static mostRecentCellOutlet: CdkCellOutlet | null; @@ -138,7 +134,7 @@ export interface CdkCellOutletRowContext { // @public export class CdkColumnDef implements CanStick { - constructor(_table?: any); + constructor(...args: unknown[]); cell: CdkCellDef; _columnCssClassName: string[]; cssClassFriendlyName: string; @@ -167,12 +163,12 @@ export class CdkColumnDef implements CanStick { // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public export class CdkFooterCell extends BaseCdkCell { - constructor(columnDef: CdkColumnDef, elementRef: ElementRef); + constructor(...args: unknown[]); // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) @@ -181,8 +177,7 @@ export class CdkFooterCell extends BaseCdkCell { // @public export class CdkFooterCellDef implements CellDef { - constructor(template: TemplateRef); - // (undocumented) + constructor(...args: unknown[]); template: TemplateRef; // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; @@ -200,7 +195,7 @@ export class CdkFooterRow { // @public export class CdkFooterRowDef extends BaseRowDef implements CanStick, OnChanges { - constructor(template: TemplateRef, _differs: IterableDiffers, _table?: any); + constructor(...args: unknown[]); hasStickyChanged(): boolean; // (undocumented) static ngAcceptInputType_sticky: unknown; @@ -214,12 +209,12 @@ export class CdkFooterRowDef extends BaseRowDef implements CanStick, OnChanges { // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public export class CdkHeaderCell extends BaseCdkCell { - constructor(columnDef: CdkColumnDef, elementRef: ElementRef); + constructor(...args: unknown[]); // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) @@ -228,8 +223,7 @@ export class CdkHeaderCell extends BaseCdkCell { // @public export class CdkHeaderCellDef implements CellDef { - constructor(template: TemplateRef); - // (undocumented) + constructor(...args: unknown[]); template: TemplateRef; // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; @@ -247,7 +241,7 @@ export class CdkHeaderRow { // @public export class CdkHeaderRowDef extends BaseRowDef implements CanStick, OnChanges { - constructor(template: TemplateRef, _differs: IterableDiffers, _table?: any); + constructor(...args: unknown[]); hasStickyChanged(): boolean; // (undocumented) static ngAcceptInputType_sticky: unknown; @@ -261,12 +255,12 @@ export class CdkHeaderRowDef extends BaseRowDef implements CanStick, OnChanges { // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public export class CdkNoDataRow { - constructor(templateRef: TemplateRef); + constructor(...args: unknown[]); // (undocumented) _contentClassName: string; // (undocumented) @@ -295,21 +289,19 @@ export class CdkRow { // @public export class CdkRowDef extends BaseRowDef { - constructor(template: TemplateRef, _differs: IterableDiffers, _table?: any); + constructor(...args: unknown[]); // (undocumented) _table?: any; when: (index: number, rowData: T) => boolean; // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration, "[cdkRowDef]", never, { "columns": { "alias": "cdkRowDefColumns"; "required": false; }; "when": { "alias": "cdkRowDefWhen"; "required": false; }; }, {}, never, never, true, never>; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration, [null, null, { optional: true; }]>; + static ɵfac: i0.ɵɵFactoryDeclaration, never>; } // @public export class CdkTable implements AfterContentInit, AfterContentChecked, CollectionViewer, OnDestroy, OnInit { - constructor(_differs: IterableDiffers, _changeDetectorRef: ChangeDetectorRef, _elementRef: ElementRef, role: string, _dir: Directionality, _document: any, _platform: Platform, _viewRepeater: _ViewRepeater, RowContext>, _coalescedStyleScheduler: _CoalescedStyleScheduler, _viewportRuler: ViewportRuler, - _stickyPositioningListener: StickyPositioningListener, - _unusedNgZone?: NgZone); + constructor(...args: unknown[]); addColumnDef(columnDef: CdkColumnDef): void; addFooterRowDef(footerRowDef: CdkFooterRowDef): void; addHeaderRowDef(headerRowDef: CdkHeaderRowDef): void; @@ -329,9 +321,9 @@ export class CdkTable implements AfterContentInit, AfterContentChecked, Colle // (undocumented) protected readonly _differs: IterableDiffers; // (undocumented) - protected readonly _dir: Directionality; + protected readonly _dir: Directionality | null; // (undocumented) - protected readonly _elementRef: ElementRef; + protected readonly _elementRef: ElementRef; get fixedLayout(): boolean; set fixedLayout(value: boolean); // (undocumented) @@ -373,7 +365,7 @@ export class CdkTable implements AfterContentInit, AfterContentChecked, Colle _rowOutlet: DataRowOutlet; setNoDataRow(noDataRow: CdkNoDataRow | null): void; protected stickyCssClass: string; - // @deprecated (undocumented) + // (undocumented) protected readonly _stickyPositioningListener: StickyPositioningListener; get trackBy(): TrackByFunction; set trackBy(fn: TrackByFunction); @@ -389,7 +381,7 @@ export class CdkTable implements AfterContentInit, AfterContentChecked, Colle // (undocumented) static ɵcmp: i0.ɵɵComponentDeclaration, "cdk-table, table[cdk-table]", ["cdkTable"], { "trackBy": { "alias": "trackBy"; "required": false; }; "dataSource": { "alias": "dataSource"; "required": false; }; "multiTemplateDataRows": { "alias": "multiTemplateDataRows"; "required": false; }; "fixedLayout": { "alias": "fixedLayout"; "required": false; }; }, { "contentChanged": "contentChanged"; }, ["_noDataRow", "_contentColumnDefs", "_contentRowDefs", "_contentHeaderRowDefs", "_contentFooterRowDefs"], ["caption", "colgroup, col", "*"], true, never>; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration, [null, null, null, { attribute: "role"; }, { optional: true; }, null, null, null, null, null, { optional: true; skipSelf: true; }, { optional: true; }]>; + static ɵfac: i0.ɵɵFactoryDeclaration, never>; } // @public @@ -407,7 +399,7 @@ export class CdkTableModule { // @public export class CdkTextColumn implements OnDestroy, OnInit { - constructor(_table: CdkTable, _options: TextColumnOptions); + constructor(...args: unknown[]); cell: CdkCellDef; columnDef: CdkColumnDef; _createDefaultHeaderText(): string; @@ -426,7 +418,7 @@ export class CdkTextColumn implements OnDestroy, OnInit { // (undocumented) static ɵcmp: i0.ɵɵComponentDeclaration, "cdk-text-column", never, { "name": { "alias": "name"; "required": false; }; "headerText": { "alias": "headerText"; "required": false; }; "dataAccessor": { "alias": "dataAccessor"; "required": false; }; "justify": { "alias": "justify"; "required": false; }; }, {}, never, never, true, never>; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration, [{ optional: true; }, { optional: true; }]>; + static ɵfac: i0.ɵɵFactoryDeclaration, never>; } // @public @@ -440,7 +432,7 @@ export const _COALESCED_STYLE_SCHEDULER: InjectionToken<_CoalescedStyleScheduler // @public export class _CoalescedStyleScheduler { - constructor(_unusedNgZone?: NgZone); + constructor(...args: unknown[]); schedule(task: () => unknown): void; scheduleEnd(task: () => unknown): void; // (undocumented) @@ -454,9 +446,9 @@ export type Constructor = new (...args: any[]) => T; // @public export class DataRowOutlet implements RowOutlet { - constructor(viewContainer: ViewContainerRef, elementRef: ElementRef); + constructor(...args: unknown[]); // (undocumented) - elementRef: ElementRef; + elementRef: ElementRef; // (undocumented) viewContainer: ViewContainerRef; // (undocumented) @@ -469,9 +461,9 @@ export { DataSource } // @public export class FooterRowOutlet implements RowOutlet { - constructor(viewContainer: ViewContainerRef, elementRef: ElementRef); + constructor(...args: unknown[]); // (undocumented) - elementRef: ElementRef; + elementRef: ElementRef; // (undocumented) viewContainer: ViewContainerRef; // (undocumented) @@ -482,9 +474,9 @@ export class FooterRowOutlet implements RowOutlet { // @public export class HeaderRowOutlet implements RowOutlet { - constructor(viewContainer: ViewContainerRef, elementRef: ElementRef); + constructor(...args: unknown[]); // (undocumented) - elementRef: ElementRef; + elementRef: ElementRef; // (undocumented) viewContainer: ViewContainerRef; // (undocumented) @@ -498,9 +490,9 @@ export function mixinHasStickyInput>(base: T): CanStic // @public export class NoDataRowOutlet implements RowOutlet { - constructor(viewContainer: ViewContainerRef, elementRef: ElementRef); + constructor(...args: unknown[]); // (undocumented) - elementRef: ElementRef; + elementRef: ElementRef; // (undocumented) viewContainer: ViewContainerRef; // (undocumented) diff --git a/tools/public_api_guard/cdk/text-field.md b/tools/public_api_guard/cdk/text-field.md index b7ce6762926a..71426016f962 100644 --- a/tools/public_api_guard/cdk/text-field.md +++ b/tools/public_api_guard/cdk/text-field.md @@ -9,12 +9,10 @@ import { DoCheck } from '@angular/core'; import { ElementRef } from '@angular/core'; import { EventEmitter } from '@angular/core'; import * as i0 from '@angular/core'; -import { NgZone } from '@angular/core'; import { NumberInput } from '@angular/cdk/coercion'; import { Observable } from 'rxjs'; import { OnDestroy } from '@angular/core'; import { OnInit } from '@angular/core'; -import { Platform } from '@angular/cdk/platform'; // @public export type AutofillEvent = { @@ -24,7 +22,7 @@ export type AutofillEvent = { // @public export class AutofillMonitor implements OnDestroy { - constructor(_platform: Platform, _ngZone: NgZone); + constructor(...args: unknown[]); monitor(element: Element): Observable; monitor(element: ElementRef): Observable; // (undocumented) @@ -39,7 +37,7 @@ export class AutofillMonitor implements OnDestroy { // @public export class CdkAutofill implements OnDestroy, OnInit { - constructor(_elementRef: ElementRef, _autofillMonitor: AutofillMonitor); + constructor(...args: unknown[]); readonly cdkAutofill: EventEmitter; // (undocumented) ngOnDestroy(): void; @@ -53,9 +51,8 @@ export class CdkAutofill implements OnDestroy, OnInit { // @public export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy { - constructor(_elementRef: ElementRef, _platform: Platform, _ngZone: NgZone, - document?: any); - protected _document?: Document; + constructor(...args: unknown[]); + protected _document?: Document | null | undefined; get enabled(): boolean; set enabled(value: boolean); get maxRows(): number; @@ -82,7 +79,7 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy { // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public (undocumented) diff --git a/tools/public_api_guard/cdk/tree.md b/tools/public_api_guard/cdk/tree.md index f22743aac0d6..b875f809c71c 100644 --- a/tools/public_api_guard/cdk/tree.md +++ b/tools/public_api_guard/cdk/tree.md @@ -8,10 +8,8 @@ import { AfterContentChecked } from '@angular/core'; import { AfterContentInit } from '@angular/core'; import { AfterViewInit } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; -import { ChangeDetectorRef } from '@angular/core'; import { CollectionViewer } from '@angular/cdk/collections'; import { DataSource } from '@angular/cdk/collections'; -import { Directionality } from '@angular/cdk/bidi'; import { ElementRef } from '@angular/core'; import { EventEmitter } from '@angular/core'; import * as i0 from '@angular/core'; @@ -57,7 +55,7 @@ export const CDK_TREE_NODE_OUTLET_NODE: InjectionToken<{}>; // @public export class CdkNestedTreeNode extends CdkTreeNode implements AfterContentInit, OnDestroy, OnInit { - constructor(elementRef: ElementRef, tree: CdkTree, _differs: IterableDiffers); + constructor(...args: unknown[]); protected _children: T[]; protected _clear(): void; // (undocumented) @@ -78,7 +76,7 @@ export class CdkNestedTreeNode extends CdkTreeNode implements Af // @public export class CdkTree implements AfterContentChecked, AfterContentInit, AfterViewInit, CollectionViewer, OnDestroy, OnInit { - constructor(_differs: IterableDiffers, _changeDetectorRef: ChangeDetectorRef); + constructor(...args: unknown[]); childrenAccessor?: (dataNode: T) => T[] | Observable; collapse(dataNode: T): void; collapseAll(): void; @@ -149,7 +147,7 @@ export class CdkTreeModule { // @public export class CdkTreeNode implements OnDestroy, OnInit, TreeKeyManagerItem { - constructor(_elementRef: ElementRef, _tree: CdkTree); + constructor(...args: unknown[]); activate(): void; readonly activation: EventEmitter; collapse(): void; @@ -217,8 +215,7 @@ export class CdkTreeNode implements OnDestroy, OnInit, TreeKeyManagerI // @public export class CdkTreeNodeDef { - constructor(template: TemplateRef); - // (undocumented) + constructor(...args: unknown[]); template: TemplateRef; when: (index: number, nodeData: T) => boolean; // (undocumented) @@ -229,15 +226,15 @@ export class CdkTreeNodeDef { // @public export class CdkTreeNodeOutlet { - constructor(viewContainer: ViewContainerRef, _node?: any); + constructor(...args: unknown[]); // (undocumented) - _node?: any; + _node?: {} | null | undefined; // (undocumented) viewContainer: ViewContainerRef; // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration; + static ɵfac: i0.ɵɵFactoryDeclaration; } // @public @@ -251,7 +248,7 @@ export class CdkTreeNodeOutletContext { // @public export class CdkTreeNodePadding implements OnDestroy { - constructor(_treeNode: CdkTreeNode, _tree: CdkTree, _element: ElementRef, _dir: Directionality); + constructor(...args: unknown[]); get indent(): number | string; set indent(indent: number | string); // (undocumented) @@ -273,12 +270,12 @@ export class CdkTreeNodePadding implements OnDestroy { // (undocumented) static ɵdir: i0.ɵɵDirectiveDeclaration, "[cdkTreeNodePadding]", never, { "level": { "alias": "cdkTreeNodePadding"; "required": false; }; "indent": { "alias": "cdkTreeNodePaddingIndent"; "required": false; }; }, {}, never, never, true, never>; // (undocumented) - static ɵfac: i0.ɵɵFactoryDeclaration, [null, null, null, { optional: true; }]>; + static ɵfac: i0.ɵɵFactoryDeclaration, never>; } // @public export class CdkTreeNodeToggle { - constructor(_tree: CdkTree, _treeNode: CdkTreeNode); + constructor(...args: unknown[]); // (undocumented) static ngAcceptInputType_recursive: unknown; recursive: boolean;