9
9
} from '@angular/core' ;
10
10
import { DOCUMENT } from '@angular/platform-browser' ;
11
11
12
- /** Flag for whether we've checked that the theme is loaded. */
13
- let hasCheckedThemePresence = false ;
12
+ /** Whether we've done the global sanity checks (e.g. a theme is loaded, there is a doctype) . */
13
+ let hasDoneGlobalChecks = false ;
14
14
15
15
export const MATERIAL_COMPATIBILITY_MODE = new OpaqueToken ( 'md-compatibility-mode' ) ;
16
16
@@ -173,12 +173,15 @@ export class CompatibilityModule {
173
173
}
174
174
175
175
constructor ( @Optional ( ) @Inject ( DOCUMENT ) private _document : any ) {
176
- this . _checkDoctype ( ) ;
177
- this . _checkTheme ( ) ;
176
+ if ( ! hasDoneGlobalChecks && isDevMode ( ) ) {
177
+ this . _checkDoctype ( ) ;
178
+ this . _checkTheme ( ) ;
179
+ hasDoneGlobalChecks = true ;
180
+ }
178
181
}
179
182
180
183
private _checkDoctype ( ) : void {
181
- if ( isDevMode ( ) && this . _document && ! this . _document . doctype ) {
184
+ if ( this . _document && ! this . _document . doctype ) {
182
185
console . warn (
183
186
'Current document does not have a doctype. This may cause ' +
184
187
'some Angular Material components not to behave as expected.'
@@ -187,25 +190,22 @@ export class CompatibilityModule {
187
190
}
188
191
189
192
private _checkTheme ( ) : void {
190
- if ( hasCheckedThemePresence || ! this . _document || ! isDevMode ( ) ) {
191
- return ;
192
- }
193
+ if ( this . _document ) {
194
+ const testElement = this . _document . createElement ( 'div' ) ;
193
195
194
- let testElement = this . _document . createElement ( 'div' ) ;
196
+ testElement . classList . add ( 'mat-theme-loaded-marker' ) ;
197
+ this . _document . body . appendChild ( testElement ) ;
195
198
196
- testElement . classList . add ( 'mat-theme-loaded-marker' ) ;
197
- this . _document . body . appendChild ( testElement ) ;
199
+ if ( getComputedStyle ( testElement ) . display !== 'none' ) {
200
+ console . warn (
201
+ 'Could not find Angular Material core theme. Most Material ' +
202
+ 'components may not work as expected. For more info refer ' +
203
+ 'to the theming guide: https://material.angular.io/guide/theming'
204
+ ) ;
205
+ }
198
206
199
- if ( getComputedStyle ( testElement ) . display !== 'none' ) {
200
- console . warn (
201
- 'Could not find Angular Material core theme. Most Material ' +
202
- 'components may not work as expected. For more info refer ' +
203
- 'to the theming guide: https://github.com/angular/material2/blob/master/guides/theming.md'
204
- ) ;
207
+ this . _document . body . removeChild ( testElement ) ;
205
208
}
206
-
207
- this . _document . body . removeChild ( testElement ) ;
208
- hasCheckedThemePresence = true ;
209
209
}
210
210
}
211
211
0 commit comments