@@ -33,7 +33,8 @@ export class LiveAnnouncer implements OnDestroy {
33
33
34
34
constructor (
35
35
@Optional ( ) @Inject ( LIVE_ANNOUNCER_ELEMENT_TOKEN ) elementToken : any ,
36
- @Inject ( DOCUMENT ) private _document : any ) {
36
+ @Inject ( DOCUMENT ) private _document : any ,
37
+ private _ngZone : NgZone ) {
37
38
38
39
// We inject the live element and document as `any` because the constructor signature cannot
39
40
// reference browser globals (HTMLElement, Document) on non-browser environments, since having
@@ -58,11 +59,13 @@ export class LiveAnnouncer implements OnDestroy {
58
59
// - With Chrome and IE11 with NVDA or JAWS, a repeated (identical) message won't be read a
59
60
// second time without clearing and then using a non-zero delay.
60
61
// (using JAWS 17 at time of this writing).
61
- return new Promise ( resolve => {
62
- setTimeout ( ( ) => {
63
- this . _liveElement . textContent = message ;
64
- resolve ( ) ;
65
- } , 100 ) ;
62
+ return this . _ngZone . runOutsideAngular ( ( ) => {
63
+ return new Promise ( resolve => {
64
+ setTimeout ( ( ) => {
65
+ this . _liveElement . textContent = message ;
66
+ resolve ( ) ;
67
+ } , 100 ) ;
68
+ } ) ;
66
69
} ) ;
67
70
}
68
71
@@ -73,7 +76,7 @@ export class LiveAnnouncer implements OnDestroy {
73
76
}
74
77
75
78
private _createLiveElement ( ) : HTMLElement {
76
- let liveEl = this . _document . createElement ( 'div' ) ;
79
+ const liveEl = this . _document . createElement ( 'div' ) ;
77
80
78
81
liveEl . classList . add ( 'cdk-live-announcer-element' ) ;
79
82
liveEl . classList . add ( 'cdk-visually-hidden' ) ;
@@ -134,8 +137,8 @@ export class CdkAriaLive implements OnDestroy {
134
137
135
138
/** @docs -private @deprecated @breaking-change 7.0.0 */
136
139
export function LIVE_ANNOUNCER_PROVIDER_FACTORY (
137
- parentDispatcher : LiveAnnouncer , liveElement : any , _document : any ) {
138
- return parentDispatcher || new LiveAnnouncer ( liveElement , _document ) ;
140
+ parentDispatcher : LiveAnnouncer , liveElement : any , _document : any , ngZone : NgZone ) {
141
+ return parentDispatcher || new LiveAnnouncer ( liveElement , _document , ngZone ) ;
139
142
}
140
143
141
144
@@ -147,6 +150,7 @@ export const LIVE_ANNOUNCER_PROVIDER: Provider = {
147
150
[ new Optional ( ) , new SkipSelf ( ) , LiveAnnouncer ] ,
148
151
[ new Optional ( ) , new Inject ( LIVE_ANNOUNCER_ELEMENT_TOKEN ) ] ,
149
152
DOCUMENT ,
153
+ NgZone ,
150
154
] ,
151
155
useFactory : LIVE_ANNOUNCER_PROVIDER_FACTORY
152
156
} ;
0 commit comments