@@ -6,14 +6,29 @@ import {
66 Inject ,
77 Optional ,
88 isDevMode ,
9+ ElementRef ,
910} from '@angular/core' ;
1011import { DOCUMENT } from '@angular/platform-browser' ;
12+ import { MdError } from '../errors/error' ;
1113
1214/** Whether we've done the global sanity checks (e.g. a theme is loaded, there is a doctype). */
1315let hasDoneGlobalChecks = false ;
1416
1517export const MATERIAL_COMPATIBILITY_MODE = new OpaqueToken ( 'md-compatibility-mode' ) ;
1618
19+ /**
20+ * Exception thrown if the consumer has used an invalid Material prefix on a component.
21+ * @docs -private
22+ */
23+ export class MdCompatibilityInvalidPrefixError extends MdError {
24+ constructor ( prefix : string , nodeName : string ) {
25+ super (
26+ `The "${ prefix } -" prefix cannot be used in ng-material v1 compatibility mode. ` +
27+ `It was used on an "${ nodeName . toLowerCase ( ) } " element.`
28+ ) ;
29+ }
30+ }
31+
1732/** Selector that matches all elements that may have style collisions with AngularJS Material. */
1833export const MAT_ELEMENTS_SELECTOR = `
1934 [mat-button],
@@ -137,19 +152,25 @@ export const MD_ELEMENTS_SELECTOR = `
137152/** Directive that enforces that the `mat-` prefix cannot be used. */
138153@Directive ( { selector : MAT_ELEMENTS_SELECTOR } )
139154export class MatPrefixRejector {
140- constructor ( @Optional ( ) @Inject ( MATERIAL_COMPATIBILITY_MODE ) isCompatibilityMode : boolean ) {
155+ constructor (
156+ @Optional ( ) @Inject ( MATERIAL_COMPATIBILITY_MODE ) isCompatibilityMode : boolean ,
157+ elementRef : ElementRef ) {
158+
141159 if ( ! isCompatibilityMode ) {
142- throw Error ( 'The " mat-" prefix cannot be used out of ng-material v1 compatibility mode.' ) ;
160+ throw new MdCompatibilityInvalidPrefixError ( ' mat' , elementRef . nativeElement . nodeName ) ;
143161 }
144162 }
145163}
146164
147165/** Directive that enforces that the `md-` prefix cannot be used. */
148166@Directive ( { selector : MD_ELEMENTS_SELECTOR } )
149167export class MdPrefixRejector {
150- constructor ( @Optional ( ) @Inject ( MATERIAL_COMPATIBILITY_MODE ) isCompatibilityMode : boolean ) {
168+ constructor (
169+ @Optional ( ) @Inject ( MATERIAL_COMPATIBILITY_MODE ) isCompatibilityMode : boolean ,
170+ elementRef : ElementRef ) {
171+
151172 if ( isCompatibilityMode ) {
152- throw Error ( 'The "md-" prefix cannot be used in ng-material v1 compatibility mode.' ) ;
173+ throw new MdCompatibilityInvalidPrefixError ( 'md' , elementRef . nativeElement . nodeName ) ;
153174 }
154175 }
155176}
0 commit comments