@@ -14,6 +14,7 @@ import {
14
14
Optional ,
15
15
Provider ,
16
16
SkipSelf ,
17
+ NgZone ,
17
18
} from '@angular/core' ;
18
19
import { LIVE_ANNOUNCER_ELEMENT_TOKEN } from './live-announcer-token' ;
19
20
@@ -27,7 +28,8 @@ export class LiveAnnouncer implements OnDestroy {
27
28
28
29
constructor (
29
30
@Optional ( ) @Inject ( LIVE_ANNOUNCER_ELEMENT_TOKEN ) elementToken : any ,
30
- @Inject ( DOCUMENT ) private _document : any ) {
31
+ @Inject ( DOCUMENT ) private _document : any ,
32
+ private _ngZone : NgZone ) {
31
33
32
34
// We inject the live element as `any` because the constructor signature cannot reference
33
35
// browser globals (HTMLElement) on non-browser environments, since having a class decorator
@@ -52,11 +54,13 @@ export class LiveAnnouncer implements OnDestroy {
52
54
// - With Chrome and IE11 with NVDA or JAWS, a repeated (identical) message won't be read a
53
55
// second time without clearing and then using a non-zero delay.
54
56
// (using JAWS 17 at time of this writing).
55
- return new Promise ( resolve => {
56
- setTimeout ( ( ) => {
57
- this . _liveElement . textContent = message ;
58
- resolve ( ) ;
59
- } , 100 ) ;
57
+ return this . _ngZone . runOutsideAngular ( ( ) => {
58
+ return new Promise ( resolve => {
59
+ setTimeout ( ( ) => {
60
+ this . _liveElement . textContent = message ;
61
+ resolve ( ) ;
62
+ } , 100 ) ;
63
+ } ) ;
60
64
} ) ;
61
65
}
62
66
@@ -67,7 +71,7 @@ export class LiveAnnouncer implements OnDestroy {
67
71
}
68
72
69
73
private _createLiveElement ( ) : Element {
70
- let liveEl = this . _document . createElement ( 'div' ) ;
74
+ const liveEl = this . _document . createElement ( 'div' ) ;
71
75
72
76
liveEl . classList . add ( 'cdk-visually-hidden' ) ;
73
77
liveEl . setAttribute ( 'aria-atomic' , 'true' ) ;
@@ -83,8 +87,8 @@ export class LiveAnnouncer implements OnDestroy {
83
87
84
88
/** @docs -private @deprecated @deletion-target 7.0.0 */
85
89
export function LIVE_ANNOUNCER_PROVIDER_FACTORY (
86
- parentDispatcher : LiveAnnouncer , liveElement : any , _document : any ) {
87
- return parentDispatcher || new LiveAnnouncer ( liveElement , _document ) ;
90
+ parentDispatcher : LiveAnnouncer , liveElement : any , _document : any , ngZone : NgZone ) {
91
+ return parentDispatcher || new LiveAnnouncer ( liveElement , _document , ngZone ) ;
88
92
}
89
93
90
94
/** @docs -private @deprecated @deletion-target 7.0.0 */
@@ -95,6 +99,7 @@ export const LIVE_ANNOUNCER_PROVIDER: Provider = {
95
99
[ new Optional ( ) , new SkipSelf ( ) , LiveAnnouncer ] ,
96
100
[ new Optional ( ) , new Inject ( LIVE_ANNOUNCER_ELEMENT_TOKEN ) ] ,
97
101
DOCUMENT ,
102
+ NgZone ,
98
103
] ,
99
104
useFactory : LIVE_ANNOUNCER_PROVIDER_FACTORY
100
105
} ;
0 commit comments