fix(core): log warning if doctype is missing (#2849)

Logs a warning if the user's document doesn't have a doctype. This has been an issue in the past with some hard-to-track-down bugs which ended up being due to the browser running in quirks mode.

Fixes #2351.
This commit is contained in:
Kristiyan Kostadinov
2017-03-20 23:54:51 +01:00
committed by Jeremy Elbourn
parent 5c1474d610
commit 22b0660103
+12 -1
View File
@@ -5,7 +5,9 @@ import {
OpaqueToken,
Inject,
Optional,
isDevMode,
} from '@angular/core';
import {DOCUMENT} from '@angular/platform-browser';
export const MATERIAL_COMPATIBILITY_MODE = new OpaqueToken('md-compatibility-mode');
@@ -71,7 +73,7 @@ export const MAT_ELEMENTS_SELECTOR = `
mat-toolbar`;
/** Selector that matches all elements that may have style collisions with AngularJS Material. */
export const MD_ELEMENTS_SELECTOR = `
export const MD_ELEMENTS_SELECTOR = `
[md-button],
[md-dialog-actions],
[md-dialog-close],
@@ -167,6 +169,15 @@ export class CompatibilityModule {
providers: [],
};
}
constructor(@Optional() @Inject(DOCUMENT) document: any) {
if (isDevMode() && typeof document && !document.doctype) {
console.warn(
'Current document does not have a doctype. This may cause ' +
'some Angular Material components not to behave as expected.'
);
}
}
}