7
7
*/
8
8
9
9
import { NgModule , InjectionToken , Optional , Inject , isDevMode } from '@angular/core' ;
10
+ import { HammerLoader , HAMMER_LOADER } from '@angular/platform-browser' ;
10
11
import { BidiModule } from '@angular/cdk/bidi' ;
11
12
12
13
@@ -44,7 +45,10 @@ export class MatCommonModule {
44
45
/** Reference to the global 'window' object. */
45
46
private _window = typeof window === 'object' && window ? window : null ;
46
47
47
- constructor ( @Optional ( ) @Inject ( MATERIAL_SANITY_CHECKS ) private _sanityChecksEnabled : boolean ) {
48
+ constructor (
49
+ @Optional ( ) @Inject ( MATERIAL_SANITY_CHECKS ) private _sanityChecksEnabled : boolean ,
50
+ @Optional ( ) @Inject ( HAMMER_LOADER ) private _hammerLoader ?: HammerLoader ) {
51
+
48
52
if ( this . _areChecksEnabled ( ) && ! this . _hasDoneGlobalChecks ) {
49
53
this . _checkDoctypeIsDefined ( ) ;
50
54
this . _checkThemeIsPresent ( ) ;
@@ -74,27 +78,29 @@ export class MatCommonModule {
74
78
private _checkThemeIsPresent ( ) : void {
75
79
// We need to assert that the `body` is defined, because these checks run very early
76
80
// and the `body` won't be defined if the consumer put their scripts in the `head`.
77
- if ( this . _document && this . _document . body && typeof getComputedStyle = == 'function' ) {
78
- const testElement = this . _document . createElement ( 'div' ) ;
79
-
80
- testElement . classList . add ( 'mat-theme-loaded-marker' ) ;
81
- this . _document . body . appendChild ( testElement ) ;
82
-
83
- const computedStyle = getComputedStyle ( testElement ) ;
84
-
85
- // In some situations the computed style of the test element can be null. For example in
86
- // Firefox, the computed style is null if an application is running inside of a hidden iframe.
87
- // See: https://bugzilla.mozilla.org/show_bug.cgi?id=548397
88
- if ( computedStyle && computedStyle . display !== 'none' ) {
89
- console . warn (
90
- 'Could not find Angular Material core theme. Most Material ' +
91
- 'components may not work as expected. For more info refer ' +
92
- 'to the theming guide: https://material.angular.io/guide/theming'
93
- ) ;
94
- }
95
-
96
- this . _document . body . removeChild ( testElement ) ;
81
+ if ( ! this . _document || ! this . _document . body || typeof getComputedStyle ! == 'function' ) {
82
+ return ;
83
+ }
84
+
85
+ const testElement = this . _document . createElement ( 'div' ) ;
86
+
87
+ testElement . classList . add ( 'mat-theme-loaded-marker' ) ;
88
+ this . _document . body . appendChild ( testElement ) ;
89
+
90
+ const computedStyle = getComputedStyle ( testElement ) ;
91
+
92
+ // In some situations the computed style of the test element can be null. For example in
93
+ // Firefox, the computed style is null if an application is running inside of a hidden iframe.
94
+ // See: https://bugzilla.mozilla.org/show_bug.cgi?id=548397
95
+ if ( computedStyle && computedStyle . display !== 'none' ) {
96
+ console . warn (
97
+ 'Could not find Angular Material core theme. Most Material ' +
98
+ 'components may not work as expected. For more info refer ' +
99
+ 'to the theming guide: https://material.angular.io/guide/theming'
100
+ ) ;
97
101
}
102
+
103
+ this . _document . body . removeChild ( testElement ) ;
98
104
}
99
105
100
106
/** Checks whether HammerJS is available. */
@@ -103,7 +109,7 @@ export class MatCommonModule {
103
109
return ;
104
110
}
105
111
106
- if ( this . _areChecksEnabled ( ) && ! this . _window [ 'Hammer' ] ) {
112
+ if ( this . _areChecksEnabled ( ) && ! this . _window [ 'Hammer' ] && ! this . _hammerLoader ) {
107
113
console . warn (
108
114
'Could not find HammerJS. Certain Angular Material components may not work correctly.' ) ;
109
115
}
0 commit comments