@@ -187,10 +187,7 @@ const MAX_WIDTH = 200;
187
187
} ,
188
188
} )
189
189
export class MatTooltip implements OnDestroy , AfterViewInit {
190
- private _overlay = inject ( Overlay ) ;
191
190
private _elementRef = inject < ElementRef < HTMLElement > > ( ElementRef ) ;
192
- private _scrollDispatcher = inject ( ScrollDispatcher ) ;
193
- private _viewContainerRef = inject ( ViewContainerRef ) ;
194
191
private _ngZone = inject ( NgZone ) ;
195
192
private _platform = inject ( Platform ) ;
196
193
private _ariaDescriber = inject ( AriaDescriber ) ;
@@ -209,7 +206,6 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
209
206
private _positionAtOrigin : boolean = false ;
210
207
private _disabled : boolean = false ;
211
208
private _tooltipClass : string | string [ ] | Set < string > | { [ key : string ] : any } ;
212
- private _scrollStrategy = inject ( MAT_TOOLTIP_SCROLL_STRATEGY ) ;
213
209
private _viewInitialized = false ;
214
210
private _pointerExitEventsInitialized = false ;
215
211
private readonly _tooltipComponent = TooltipComponent ;
@@ -362,9 +358,6 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
362
358
private readonly _passiveListeners : ( readonly [ string , EventListenerOrEventListenerObject ] ) [ ] =
363
359
[ ] ;
364
360
365
- /** Reference to the current document. */
366
- private _document = inject ( DOCUMENT ) ;
367
-
368
361
/** Timer started at the last `touchstart` event. */
369
362
private _touchstartTimeout : null | ReturnType < typeof setTimeout > = null ;
370
363
@@ -462,7 +455,8 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
462
455
const overlayRef = this . _createOverlay ( origin ) ;
463
456
this . _detach ( ) ;
464
457
this . _portal =
465
- this . _portal || new ComponentPortal ( this . _tooltipComponent , this . _viewContainerRef ) ;
458
+ this . _portal ||
459
+ new ComponentPortal ( this . _tooltipComponent , this . _injector . get ( ViewContainerRef ) ) ;
466
460
const instance = ( this . _tooltipInstance = overlayRef . attach ( this . _portal ) . instance ) ;
467
461
instance . _triggerElement = this . _elementRef . nativeElement ;
468
462
instance . _mouseLeaveHideDelay = this . _hideDelay ;
@@ -512,12 +506,14 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
512
506
this . _detach ( ) ;
513
507
}
514
508
515
- const scrollableAncestors = this . _scrollDispatcher . getAncestorScrollContainers (
516
- this . _elementRef ,
517
- ) ;
509
+ const scrollableAncestors = this . _injector
510
+ . get ( ScrollDispatcher )
511
+ . getAncestorScrollContainers ( this . _elementRef ) ;
512
+
513
+ const overlay = this . _injector . get ( Overlay ) ;
518
514
519
515
// Create connected position strategy that listens for scroll events to reposition.
520
- const strategy = this . _overlay
516
+ const strategy = overlay
521
517
. position ( )
522
518
. flexibleConnectedTo ( this . positionAtOrigin ? origin || this . _elementRef : this . _elementRef )
523
519
. withTransformOriginOn ( `.${ this . _cssClassPrefix } -tooltip` )
@@ -537,11 +533,11 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
537
533
}
538
534
} ) ;
539
535
540
- this . _overlayRef = this . _overlay . create ( {
536
+ this . _overlayRef = overlay . create ( {
541
537
direction : this . _dir ,
542
538
positionStrategy : strategy ,
543
539
panelClass : `${ this . _cssClassPrefix } -${ PANEL_CLASS } ` ,
544
- scrollStrategy : this . _scrollStrategy ( ) ,
540
+ scrollStrategy : this . _injector . get ( MAT_TOOLTIP_SCROLL_STRATEGY ) ( ) ,
545
541
} ) ;
546
542
547
543
this . _updatePosition ( this . _overlayRef ) ;
@@ -874,7 +870,9 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
874
870
/** Listener for the `wheel` event on the element. */
875
871
private _wheelListener ( event : WheelEvent ) {
876
872
if ( this . _isTooltipVisible ( ) ) {
877
- const elementUnderPointer = this . _document . elementFromPoint ( event . clientX , event . clientY ) ;
873
+ const elementUnderPointer = this . _injector
874
+ . get ( DOCUMENT )
875
+ . elementFromPoint ( event . clientX , event . clientY ) ;
878
876
const element = this . _elementRef . nativeElement ;
879
877
880
878
// On non-touch devices we depend on the `mouseleave` event to close the tooltip, but it
0 commit comments