@@ -16,14 +16,13 @@ import {
16
16
Directive ,
17
17
ElementRef ,
18
18
EventEmitter ,
19
- Inject ,
20
19
Injectable ,
21
20
InjectionToken ,
22
21
NgZone ,
23
22
OnDestroy ,
24
- Optional ,
25
23
Output ,
26
24
AfterViewInit ,
25
+ inject ,
27
26
} from '@angular/core' ;
28
27
import { Observable , of as observableOf , Subject , Subscription } from 'rxjs' ;
29
28
import { takeUntil } from 'rxjs/operators' ;
@@ -85,6 +84,10 @@ const captureEventListenerOptions = normalizePassiveListenerOptions({
85
84
/** Monitors mouse and keyboard events to determine the cause of focus events. */
86
85
@Injectable ( { providedIn : 'root' } )
87
86
export class FocusMonitor implements OnDestroy {
87
+ private _ngZone = inject ( NgZone ) ;
88
+ private _platform = inject ( Platform ) ;
89
+ private readonly _inputModalityDetector = inject ( InputModalityDetector ) ;
90
+
88
91
/** The focus origin that the next focus event is a result of. */
89
92
private _origin : FocusOrigin = null ;
90
93
@@ -138,20 +141,18 @@ export class FocusMonitor implements OnDestroy {
138
141
} ;
139
142
140
143
/** Used to reference correct document/window */
141
- protected _document ?: Document ;
144
+ protected _document ? = inject ( DOCUMENT , { optional : true } ) ;
142
145
143
146
/** Subject for stopping our InputModalityDetector subscription. */
144
147
private readonly _stopInputModalityDetector = new Subject < void > ( ) ;
145
148
146
- constructor (
147
- private _ngZone : NgZone ,
148
- private _platform : Platform ,
149
- private readonly _inputModalityDetector : InputModalityDetector ,
150
- /** @breaking -change 11.0.0 make document required */
151
- @Optional ( ) @Inject ( DOCUMENT ) document : any | null ,
152
- @Optional ( ) @Inject ( FOCUS_MONITOR_DEFAULT_OPTIONS ) options : FocusMonitorOptions | null ,
153
- ) {
154
- this . _document = document ;
149
+ constructor ( ...args : unknown [ ] ) ;
150
+
151
+ constructor ( ) {
152
+ const options = inject < FocusMonitorOptions | null > ( FOCUS_MONITOR_DEFAULT_OPTIONS , {
153
+ optional : true ,
154
+ } ) ;
155
+
155
156
this . _detectionMode = options ?. detectionMode || FocusMonitorDetectionMode . IMMEDIATE ;
156
157
}
157
158
/**
@@ -619,15 +620,16 @@ export class FocusMonitor implements OnDestroy {
619
620
standalone : true ,
620
621
} )
621
622
export class CdkMonitorFocus implements AfterViewInit , OnDestroy {
623
+ private _elementRef = inject < ElementRef < HTMLElement > > ( ElementRef ) ;
624
+ private _focusMonitor = inject ( FocusMonitor ) ;
625
+
622
626
private _monitorSubscription : Subscription ;
623
627
private _focusOrigin : FocusOrigin = null ;
624
628
625
629
@Output ( ) readonly cdkFocusChange = new EventEmitter < FocusOrigin > ( ) ;
626
630
627
- constructor (
628
- private _elementRef : ElementRef < HTMLElement > ,
629
- private _focusMonitor : FocusMonitor ,
630
- ) { }
631
+ constructor ( ...args : unknown [ ] ) ;
632
+ constructor ( ) { }
631
633
632
634
get focusOrigin ( ) : FocusOrigin {
633
635
return this . _focusOrigin ;
0 commit comments