9
9
OnDestroy ,
10
10
Renderer ,
11
11
OnInit ,
12
- ChangeDetectorRef
12
+ ChangeDetectorRef ,
13
13
} from '@angular/core' ;
14
14
import {
15
15
style ,
@@ -157,7 +157,7 @@ export class MdTooltip implements OnInit, OnDestroy {
157
157
@Optional ( ) private _dir : Dir ) {
158
158
159
159
// The mouse events shouldn't be bound on iOS devices, because
160
- // they can prevent the first tap from firing it's click event.
160
+ // they can prevent the first tap from firing its click event.
161
161
if ( ! _platform . IOS ) {
162
162
_renderer . listen ( _elementRef . nativeElement , 'mouseenter' , ( ) => this . show ( ) ) ;
163
163
_renderer . listen ( _elementRef . nativeElement , 'mouseleave' , ( ) => this . hide ( ) ) ;
@@ -313,6 +313,8 @@ export class MdTooltip implements OnInit, OnDestroy {
313
313
// Must wait for the message to be painted to the tooltip so that the overlay can properly
314
314
// calculate the correct positioning based on the size of the text.
315
315
this . _tooltipInstance . message = message ;
316
+ this . _tooltipInstance . _markForCheck ( ) ;
317
+
316
318
this . _ngZone . onMicrotaskEmpty . first ( ) . subscribe ( ( ) => {
317
319
if ( this . _tooltipInstance ) {
318
320
this . _overlayRef . updatePosition ( ) ;
@@ -394,8 +396,8 @@ export class TooltipComponent {
394
396
395
397
// Mark for check so if any parent component has set the
396
398
// ChangeDetectionStrategy to OnPush it will be checked anyways
397
- this . _changeDetectorRef . markForCheck ( ) ;
398
- setTimeout ( ( ) => { this . _closeOnInteraction = true ; } , 0 ) ;
399
+ this . _markForCheck ( ) ;
400
+ setTimeout ( ( ) => this . _closeOnInteraction = true , 0 ) ;
399
401
} , delay ) ;
400
402
}
401
403
@@ -415,7 +417,7 @@ export class TooltipComponent {
415
417
416
418
// Mark for check so if any parent component has set the
417
419
// ChangeDetectionStrategy to OnPush it will be checked anyways
418
- this . _changeDetectorRef . markForCheck ( ) ;
420
+ this . _markForCheck ( ) ;
419
421
} , delay ) ;
420
422
}
421
423
@@ -441,8 +443,8 @@ export class TooltipComponent {
441
443
case 'after' : this . _transformOrigin = isLtr ? 'left' : 'right' ; break ;
442
444
case 'left' : this . _transformOrigin = 'right' ; break ;
443
445
case 'right' : this . _transformOrigin = 'left' ; break ;
444
- case 'above' : this . _transformOrigin = 'bottom' ; break ;
445
- case 'below' : this . _transformOrigin = 'top' ; break ;
446
+ case 'above' : this . _transformOrigin = 'bottom' ; break ;
447
+ case 'below' : this . _transformOrigin = 'top' ; break ;
446
448
default : throw new MdTooltipInvalidPositionError ( value ) ;
447
449
}
448
450
}
@@ -463,4 +465,13 @@ export class TooltipComponent {
463
465
this . hide ( 0 ) ;
464
466
}
465
467
}
468
+
469
+ /**
470
+ * Marks that the tooltip needs to be checked in the next change detection run.
471
+ * Mainly used for rendering the initial text before positioning a tooltip, which
472
+ * can be problematic in components with OnPush change detection.
473
+ */
474
+ _markForCheck ( ) : void {
475
+ this . _changeDetectorRef . markForCheck ( ) ;
476
+ }
466
477
}
0 commit comments