@@ -87,7 +87,7 @@ const modalityEventListenerOptions = normalizePassiveListenerOptions({
8787 * update the input modality to keyboard, but in general this service's behavior is largely
8888 * undefined.
8989 */
90- @Injectable ( { providedIn : 'root' } )
90+ @Injectable ( { providedIn : 'root' } )
9191export class InputModalityDetector implements OnDestroy {
9292 /** Emits whenever an input modality is detected. */
9393 readonly modalityDetected : Observable < InputModality > ;
@@ -185,21 +185,22 @@ export class InputModalityDetector implements OnDestroy {
185185
186186 // If we're not in a browser, this service should do nothing, as there's no relevant input
187187 // 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+ }
196195 }
197196
198197 ngOnDestroy ( ) {
199- if ( ! this . _platform . isBrowser ) { return ; }
198+ this . _modality . complete ( ) ;
200199
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+ }
204205 }
205206}
0 commit comments