6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
+ import { Platform } from '@angular/cdk/platform' ;
9
10
import {
10
11
ChangeDetectionStrategy ,
11
12
Component ,
@@ -19,6 +20,7 @@ import {
19
20
SimpleChanges ,
20
21
OnDestroy ,
21
22
AfterViewChecked ,
23
+ inject ,
22
24
} from '@angular/core' ;
23
25
import { take } from 'rxjs/operators' ;
24
26
@@ -71,6 +73,8 @@ let calendarBodyId = 1;
71
73
changeDetection : ChangeDetectionStrategy . OnPush ,
72
74
} )
73
75
export class MatCalendarBody < D = any > implements OnChanges , OnDestroy , AfterViewChecked {
76
+ private _platform = inject ( Platform ) ;
77
+
74
78
/**
75
79
* Used to skip the next focus event when rendering the preview range.
76
80
* We need a flag like this, because some browsers fire focus events asynchronously.
@@ -177,8 +181,11 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
177
181
element . addEventListener ( 'blur' , this . _leaveHandler , true ) ;
178
182
element . addEventListener ( 'mousedown' , this . _mousedownHandler ) ;
179
183
element . addEventListener ( 'touchstart' , this . _mousedownHandler ) ;
180
- window . addEventListener ( 'mouseup' , this . _mouseupHandler ) ;
181
- window . addEventListener ( 'touchend' , this . _touchendHandler ) ;
184
+
185
+ if ( this . _platform . isBrowser ) {
186
+ window . addEventListener ( 'mouseup' , this . _mouseupHandler ) ;
187
+ window . addEventListener ( 'touchend' , this . _touchendHandler ) ;
188
+ }
182
189
} ) ;
183
190
}
184
191
@@ -232,8 +239,11 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
232
239
element . removeEventListener ( 'blur' , this . _leaveHandler , true ) ;
233
240
element . removeEventListener ( 'mousedown' , this . _mousedownHandler ) ;
234
241
element . removeEventListener ( 'touchstart' , this . _mousedownHandler ) ;
235
- window . removeEventListener ( 'mouseup' , this . _mouseupHandler ) ;
236
- window . removeEventListener ( 'touchend' , this . _touchendHandler ) ;
242
+
243
+ if ( this . _platform . isBrowser ) {
244
+ window . removeEventListener ( 'mouseup' , this . _mouseupHandler ) ;
245
+ window . removeEventListener ( 'touchend' , this . _touchendHandler ) ;
246
+ }
237
247
}
238
248
239
249
/** Returns whether a cell is active. */
0 commit comments