99} from '@angular/core' ;
1010import { DOCUMENT } from '@angular/platform-browser' ;
1111
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 ;
1414
1515export const MATERIAL_COMPATIBILITY_MODE = new OpaqueToken ( 'md-compatibility-mode' ) ;
1616
@@ -173,12 +173,15 @@ export class CompatibilityModule {
173173 }
174174
175175 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+ }
178181 }
179182
180183 private _checkDoctype ( ) : void {
181- if ( isDevMode ( ) && this . _document && ! this . _document . doctype ) {
184+ if ( this . _document && ! this . _document . doctype ) {
182185 console . warn (
183186 'Current document does not have a doctype. This may cause ' +
184187 'some Angular Material components not to behave as expected.'
@@ -187,25 +190,22 @@ export class CompatibilityModule {
187190 }
188191
189192 private _checkTheme ( ) : void {
190- if ( hasCheckedThemePresence || ! this . _document || ! isDevMode ( ) ) {
191- return ;
192- }
193+ if ( this . _document ) {
194+ const testElement = this . _document . createElement ( 'div' ) ;
193195
194- let testElement = this . _document . createElement ( 'div' ) ;
196+ testElement . classList . add ( 'mat-theme-loaded-marker' ) ;
197+ this . _document . body . appendChild ( testElement ) ;
195198
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://github.com/angular/material2/blob/master/guides/theming.md'
204+ ) ;
205+ }
198206
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 ) ;
205208 }
206-
207- this . _document . body . removeChild ( testElement ) ;
208- hasCheckedThemePresence = true ;
209209 }
210210}
211211
0 commit comments