@@ -34,6 +34,7 @@ export class LiveAnnouncer implements OnDestroy {
34
34
35
35
constructor (
36
36
@Optional ( ) @Inject ( LIVE_ANNOUNCER_ELEMENT_TOKEN ) elementToken : any ,
37
+ private _ngZone : NgZone ,
37
38
@Inject ( DOCUMENT ) _document : any ) {
38
39
39
40
// We inject the live element and document as `any` because the constructor signature cannot
@@ -60,11 +61,13 @@ export class LiveAnnouncer implements OnDestroy {
60
61
// - With Chrome and IE11 with NVDA or JAWS, a repeated (identical) message won't be read a
61
62
// second time without clearing and then using a non-zero delay.
62
63
// (using JAWS 17 at time of this writing).
63
- return new Promise ( resolve => {
64
- setTimeout ( ( ) => {
65
- this . _liveElement . textContent = message ;
66
- resolve ( ) ;
67
- } , 100 ) ;
64
+ return this . _ngZone . runOutsideAngular ( ( ) => {
65
+ return new Promise ( resolve => {
66
+ setTimeout ( ( ) => {
67
+ this . _liveElement . textContent = message ;
68
+ resolve ( ) ;
69
+ } , 100 ) ;
70
+ } ) ;
68
71
} ) ;
69
72
}
70
73
@@ -77,13 +80,13 @@ export class LiveAnnouncer implements OnDestroy {
77
80
private _createLiveElement ( ) : HTMLElement {
78
81
const elementClass = 'cdk-live-announcer-element' ;
79
82
const previousElements = this . _document . getElementsByClassName ( elementClass ) ;
83
+ const liveEl = this . _document . createElement ( 'div' ) ;
80
84
81
85
// Remove any old containers. This can happen when coming in from a server-side-rendered page.
82
86
for ( let i = 0 ; i < previousElements . length ; i ++ ) {
83
87
previousElements [ i ] . parentNode ! . removeChild ( previousElements [ i ] ) ;
84
88
}
85
89
86
- const liveEl = this . _document . createElement ( 'div' ) ;
87
90
liveEl . classList . add ( elementClass ) ;
88
91
liveEl . classList . add ( 'cdk-visually-hidden' ) ;
89
92
@@ -146,8 +149,8 @@ export class CdkAriaLive implements OnDestroy {
146
149
147
150
/** @docs -private @deprecated @breaking-change 7.0.0 */
148
151
export function LIVE_ANNOUNCER_PROVIDER_FACTORY (
149
- parentDispatcher : LiveAnnouncer , liveElement : any , _document : any ) {
150
- return parentDispatcher || new LiveAnnouncer ( liveElement , _document ) ;
152
+ parentDispatcher : LiveAnnouncer , liveElement : any , _document : any , ngZone : NgZone ) {
153
+ return parentDispatcher || new LiveAnnouncer ( liveElement , _document , ngZone ) ;
151
154
}
152
155
153
156
@@ -159,6 +162,7 @@ export const LIVE_ANNOUNCER_PROVIDER: Provider = {
159
162
[ new Optional ( ) , new SkipSelf ( ) , LiveAnnouncer ] ,
160
163
[ new Optional ( ) , new Inject ( LIVE_ANNOUNCER_ELEMENT_TOKEN ) ] ,
161
164
DOCUMENT ,
165
+ NgZone ,
162
166
] ,
163
167
useFactory : LIVE_ANNOUNCER_PROVIDER_FACTORY
164
168
} ;
0 commit comments