Skip to content

Commit

Permalink
fix(core): log warning if doctype is missing
Browse files Browse the repository at this point in the history
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 angular#2351.
  • Loading branch information
crisbeto committed Mar 19, 2017
1 parent c203589 commit 052c430
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/lib/core/compatibility/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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.'
);
}
}
}


Expand Down

0 comments on commit 052c430

Please sign in to comment.