@@ -87,7 +87,7 @@ const modalityEventListenerOptions = normalizePassiveListenerOptions({
87
87
* update the input modality to keyboard, but in general this service's behavior is largely
88
88
* undefined.
89
89
*/
90
- @Injectable ( { providedIn : 'root' } )
90
+ @Injectable ( { providedIn : 'root' } )
91
91
export class InputModalityDetector implements OnDestroy {
92
92
/** Emits whenever an input modality is detected. */
93
93
readonly modalityDetected : Observable < InputModality > ;
@@ -185,21 +185,22 @@ export class InputModalityDetector implements OnDestroy {
185
185
186
186
// If we're not in a browser, this service should do nothing, as there's no relevant input
187
187
// modality to detect.
188
- if ( ! _platform . isBrowser ) { return ; }
189
-
190
- // Add the event listeners used to detect the user's input modality.
191
- ngZone . runOutsideAngular ( ( ) => {
192
- document . addEventListener ( 'keydown' , this . _onKeydown , modalityEventListenerOptions ) ;
193
- document . addEventListener ( 'mousedown' , this . _onMousedown , modalityEventListenerOptions ) ;
194
- document . addEventListener ( 'touchstart' , this . _onTouchstart , modalityEventListenerOptions ) ;
195
- } ) ;
188
+ if ( _platform . isBrowser ) {
189
+ ngZone . runOutsideAngular ( ( ) => {
190
+ document . addEventListener ( 'keydown' , this . _onKeydown , modalityEventListenerOptions ) ;
191
+ document . addEventListener ( 'mousedown' , this . _onMousedown , modalityEventListenerOptions ) ;
192
+ document . addEventListener ( 'touchstart' , this . _onTouchstart , modalityEventListenerOptions ) ;
193
+ } ) ;
194
+ }
196
195
}
197
196
198
197
ngOnDestroy ( ) {
199
- if ( ! this . _platform . isBrowser ) { return ; }
198
+ this . _modality . complete ( ) ;
200
199
201
- document . removeEventListener ( 'keydown' , this . _onKeydown , modalityEventListenerOptions ) ;
202
- document . removeEventListener ( 'mousedown' , this . _onMousedown , modalityEventListenerOptions ) ;
203
- document . removeEventListener ( 'touchstart' , this . _onTouchstart , modalityEventListenerOptions ) ;
200
+ if ( this . _platform . isBrowser ) {
201
+ document . removeEventListener ( 'keydown' , this . _onKeydown , modalityEventListenerOptions ) ;
202
+ document . removeEventListener ( 'mousedown' , this . _onMousedown , modalityEventListenerOptions ) ;
203
+ document . removeEventListener ( 'touchstart' , this . _onTouchstart , modalityEventListenerOptions ) ;
204
+ }
204
205
}
205
206
}
0 commit comments