@@ -371,6 +371,9 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
371371 /** Emits when the component is destroyed. */
372372 private readonly _destroyed = new Subject < void > ( ) ;
373373
374+ /** Whether ngOnDestroyed has been called. */
375+ private _isDestroyed = false ;
376+
374377 constructor ( ...args : unknown [ ] ) ;
375378
376379 constructor ( ) {
@@ -443,6 +446,8 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
443446 this . _destroyed . next ( ) ;
444447 this . _destroyed . complete ( ) ;
445448
449+ this . _isDestroyed = true ;
450+
446451 this . _ariaDescriber . removeDescription ( nativeElement , this . message , 'tooltip' ) ;
447452 this . _focusMonitor . stopMonitoring ( nativeElement ) ;
448453 }
@@ -920,19 +925,24 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
920925 this . _ariaDescriptionPending = true ;
921926 this . _ariaDescriber . removeDescription ( this . _elementRef . nativeElement , oldMessage , 'tooltip' ) ;
922927
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 ;
930937
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+ }
936946 }
937947}
938948
0 commit comments