@@ -6,14 +6,29 @@ import {
6
6
Inject ,
7
7
Optional ,
8
8
isDevMode ,
9
+ ElementRef ,
9
10
} from '@angular/core' ;
10
11
import { DOCUMENT } from '@angular/platform-browser' ;
12
+ import { MdError } from '../errors/error' ;
11
13
12
14
/** Whether we've done the global sanity checks (e.g. a theme is loaded, there is a doctype). */
13
15
let hasDoneGlobalChecks = false ;
14
16
15
17
export const MATERIAL_COMPATIBILITY_MODE = new OpaqueToken ( 'md-compatibility-mode' ) ;
16
18
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
+
17
32
/** Selector that matches all elements that may have style collisions with AngularJS Material. */
18
33
export const MAT_ELEMENTS_SELECTOR = `
19
34
[mat-button],
@@ -137,19 +152,25 @@ export const MD_ELEMENTS_SELECTOR = `
137
152
/** Directive that enforces that the `mat-` prefix cannot be used. */
138
153
@Directive ( { selector : MAT_ELEMENTS_SELECTOR } )
139
154
export 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
+
141
159
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 ) ;
143
161
}
144
162
}
145
163
}
146
164
147
165
/** Directive that enforces that the `md-` prefix cannot be used. */
148
166
@Directive ( { selector : MD_ELEMENTS_SELECTOR } )
149
167
export 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
+
151
172
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 ) ;
153
174
}
154
175
}
155
176
}
0 commit comments