@@ -13,7 +13,7 @@ import {
1313 animate ,
1414 AnimationTransitionEvent ,
1515 NgZone ,
16- Optional ,
16+ Optional , OnDestroy , OnInit ,
1717} from '@angular/core' ;
1818import {
1919 Overlay ,
@@ -23,13 +23,16 @@ import {
2323 ComponentPortal ,
2424 OverlayConnectionPosition ,
2525 OriginConnectionPosition ,
26- OVERLAY_PROVIDERS ,
2726 DefaultStyleCompatibilityModeModule ,
2827} from '../core' ;
2928import { MdTooltipInvalidPositionError } from './tooltip-errors' ;
3029import { Observable } from 'rxjs/Observable' ;
3130import { Subject } from 'rxjs/Subject' ;
3231import { Dir } from '../core/rtl/dir' ;
32+ import { Scroll } from '../core/scroll/scroll' ;
33+ import { ScrollModule } from '../core/scroll/scrollable' ;
34+ import { OverlayPositionBuilder } from '../core/overlay/position/overlay-position-builder' ;
35+ import { ViewportRuler } from '../core/overlay/position/viewport-ruler' ;
3336
3437export type TooltipPosition = 'left' | 'right' | 'above' | 'below' | 'before' | 'after' ;
3538
@@ -52,7 +55,7 @@ export const TOUCHEND_HIDE_DELAY = 1500;
5255 } ,
5356 exportAs : 'mdTooltip' ,
5457} )
55- export class MdTooltip {
58+ export class MdTooltip implements OnInit , OnDestroy {
5659 _overlayRef : OverlayRef ;
5760 _tooltipInstance : TooltipComponent ;
5861
@@ -92,10 +95,23 @@ export class MdTooltip {
9295 }
9396 }
9497
95- constructor ( private _overlay : Overlay , private _elementRef : ElementRef ,
96- private _viewContainerRef : ViewContainerRef , private _ngZone : NgZone ,
98+ constructor ( private _overlay : Overlay ,
99+ private _scroll : Scroll ,
100+ private _elementRef : ElementRef ,
101+ private _viewContainerRef : ViewContainerRef ,
102+ private _ngZone : NgZone ,
97103 @Optional ( ) private _dir : Dir ) { }
98104
105+ ngOnInit ( ) {
106+ // When a scroll on the page occurs, update the position in case this tooltip needs
107+ // to be repositioned.
108+ this . _scroll . scrolled ( ) . subscribe ( ( ) => {
109+ if ( this . _overlayRef ) {
110+ this . _overlayRef . updatePosition ( ) ;
111+ }
112+ } ) ;
113+ }
114+
99115 /** Dispose the tooltip when destroyed */
100116 ngOnDestroy ( ) {
101117 if ( this . _tooltipInstance ) {
@@ -349,7 +365,7 @@ export class TooltipComponent {
349365
350366
351367@NgModule ( {
352- imports : [ OverlayModule , DefaultStyleCompatibilityModeModule ] ,
368+ imports : [ OverlayModule , DefaultStyleCompatibilityModeModule , ScrollModule ] ,
353369 exports : [ MdTooltip , TooltipComponent , DefaultStyleCompatibilityModeModule ] ,
354370 declarations : [ MdTooltip , TooltipComponent ] ,
355371 entryComponents : [ TooltipComponent ] ,
@@ -358,7 +374,12 @@ export class MdTooltipModule {
358374 static forRoot ( ) : ModuleWithProviders {
359375 return {
360376 ngModule : MdTooltipModule ,
361- providers : OVERLAY_PROVIDERS ,
377+ providers : [
378+ Overlay ,
379+ OverlayPositionBuilder ,
380+ ViewportRuler ,
381+ Scroll
382+ ]
362383 } ;
363384 }
364385}
0 commit comments