@@ -371,6 +371,9 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
371
371
/** Emits when the component is destroyed. */
372
372
private readonly _destroyed = new Subject < void > ( ) ;
373
373
374
+ /** Whether ngOnDestroyed has been called. */
375
+ private _isDestroyed = false ;
376
+
374
377
constructor ( ...args : unknown [ ] ) ;
375
378
376
379
constructor ( ) {
@@ -443,6 +446,8 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
443
446
this . _destroyed . next ( ) ;
444
447
this . _destroyed . complete ( ) ;
445
448
449
+ this . _isDestroyed = true ;
450
+
446
451
this . _ariaDescriber . removeDescription ( nativeElement , this . message , 'tooltip' ) ;
447
452
this . _focusMonitor . stopMonitoring ( nativeElement ) ;
448
453
}
@@ -920,19 +925,24 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
920
925
this . _ariaDescriptionPending = true ;
921
926
this . _ariaDescriber . removeDescription ( this . _elementRef . nativeElement , oldMessage , 'tooltip' ) ;
922
927
923
- this . _ngZone . runOutsideAngular ( ( ) => {
924
- // The `AriaDescriber` has some functionality that avoids adding a description if it's the
925
- // same as the `aria-label` of an element, however we can't know whether the tooltip trigger
926
- // has a data-bound `aria-label` or when it'll be set for the first time. We can avoid the
927
- // issue by deferring the description by a tick so Angular has time to set the `aria-label`.
928
- Promise . resolve ( ) . then ( ( ) => {
929
- this . _ariaDescriptionPending = false ;
928
+ // The `AriaDescriber` has some functionality that avoids adding a description if it's the
929
+ // same as the `aria-label` of an element, however we can't know whether the tooltip trigger
930
+ // has a data-bound `aria-label` or when it'll be set for the first time. We can avoid the
931
+ // issue by deferring the description by a tick so Angular has time to set the `aria-label`.
932
+ if ( ! this . _isDestroyed ) {
933
+ afterNextRender (
934
+ {
935
+ write : ( ) => {
936
+ this . _ariaDescriptionPending = false ;
930
937
931
- if ( this . message && ! this . disabled ) {
932
- this . _ariaDescriber . describe ( this . _elementRef . nativeElement , this . message , 'tooltip' ) ;
933
- }
934
- } ) ;
935
- } ) ;
938
+ if ( this . message && ! this . disabled ) {
939
+ this . _ariaDescriber . describe ( this . _elementRef . nativeElement , this . message , 'tooltip' ) ;
940
+ }
941
+ } ,
942
+ } ,
943
+ { injector : this . _injector } ,
944
+ ) ;
945
+ }
936
946
}
937
947
}
938
948
0 commit comments