Skip to content

Commit 70c4a07

Browse files
committed
refactor($compile): rename directive.type to directive.templateNamespace
BREAKING CHANGE (within 1.3.0-beta): `directive.type` was renamed to `directive.templateNamespace` The property name `type` was too general.
1 parent 3623019 commit 70c4a07

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

src/ng/compile.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,17 @@
219219
* * `M` - Comment: `<!-- directive: my-directive exp -->`
220220
*
221221
*
222-
* #### `type`
223-
* String representing the document type used by the markup. This is useful for templates where the root
224-
* node is non-HTML content (such as SVG or MathML). The default value is "html".
222+
* #### `templateNamespace`
223+
* String representing the document type used by the markup in the template.
224+
* AngularJS needs this information as those elements need to be created and cloned
225+
* in a special way when they are defined outside their usual containers like `<svg>` and `<math>`.
225226
*
226-
* * `html` - All root template nodes are HTML, and don't need to be wrapped. Root nodes may also be
227+
* * `html` - All root nodes in the template are HTML. Root nodes may also be
227228
* top-level elements such as `<svg>` or `<math>`.
228-
* * `svg` - The template contains only SVG content, and must be wrapped in an `<svg>` node prior to
229-
* processing.
230-
* * `math` - The template contains only MathML content, and must be wrapped in an `<math>` node prior to
231-
* processing.
229+
* * `svg` - The root nodes in the template are SVG elements (excluding `<math>`).
230+
* * `math` - The root nodes in the template are MathML elements (excluding `<svg>`).
232231
*
233-
* If no `type` is specified, then the type is considered to be html.
232+
* If no `templateNamespace` is specified, then the namespace is considered to be `html`.
234233
*
235234
* #### `template`
236235
* HTML markup that may:
@@ -1339,7 +1338,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
13391338
if (jqLiteIsTextNode(directiveValue)) {
13401339
$template = [];
13411340
} else {
1342-
$template = jqLite(wrapTemplate(directive.type, trim(directiveValue)));
1341+
$template = jqLite(wrapTemplate(directive.templateNamespace, trim(directiveValue)));
13431342
}
13441343
compileNode = $template[0];
13451344

@@ -1786,7 +1785,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
17861785
templateUrl = (isFunction(origAsyncDirective.templateUrl))
17871786
? origAsyncDirective.templateUrl($compileNode, tAttrs)
17881787
: origAsyncDirective.templateUrl,
1789-
type = origAsyncDirective.type;
1788+
templateNamespace = origAsyncDirective.templateNamespace;
17901789

17911790
$compileNode.empty();
17921791

@@ -1800,7 +1799,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
18001799
if (jqLiteIsTextNode(content)) {
18011800
$template = [];
18021801
} else {
1803-
$template = jqLite(wrapTemplate(type, trim(content)));
1802+
$template = jqLite(wrapTemplate(templateNamespace, trim(content)));
18041803
}
18051804
compileNode = $template[0];
18061805

test/ng/compileSpec.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -839,12 +839,12 @@ describe('$compile', function() {
839839
}));
840840

841841
if (window.SVGAElement) {
842-
it('should support SVG templates using directive.type=svg', function() {
842+
it('should support SVG templates using directive.templateNamespace=svg', function() {
843843
module(function() {
844844
directive('svgAnchor', valueFn({
845845
replace: true,
846846
template: '<a xlink:href="{{linkurl}}">{{text}}</a>',
847-
type: 'SVG',
847+
templateNamespace: 'SVG',
848848
scope: {
849849
linkurl: '@svgAnchor',
850850
text: '@?'
@@ -866,13 +866,13 @@ describe('$compile', function() {
866866
// and even there, the browser does not export MathML element constructors globally.
867867
// So the test is slightly limited in what it does. But as browsers begin to
868868
// implement MathML natively, this can be tightened up to be more meaningful.
869-
it('should support MathML templates using directive.type=math', function() {
869+
it('should support MathML templates using directive.templateNamespace=math', function() {
870870
module(function() {
871871
directive('pow', valueFn({
872872
replace: true,
873873
transclude: true,
874874
template: '<msup><mn>{{pow}}</mn></msup>',
875-
type: 'MATH',
875+
templateNamespace: 'MATH',
876876
scope: {
877877
pow: '@pow',
878878
},
@@ -888,6 +888,7 @@ describe('$compile', function() {
888888
$rootScope.$digest();
889889
var child = element.children().eq(0);
890890
expect(nodeName_(child)).toMatch(/msup/i);
891+
expect(child[0].constructor).toBe(Element);
891892
});
892893
});
893894
});
@@ -1736,12 +1737,12 @@ describe('$compile', function() {
17361737
}));
17371738

17381739
if (window.SVGAElement) {
1739-
it('should support SVG templates using directive.type=svg', function() {
1740+
it('should support SVG templates using directive.templateNamespace=svg', function() {
17401741
module(function() {
17411742
directive('svgAnchor', valueFn({
17421743
replace: true,
17431744
templateUrl: 'template.html',
1744-
type: 'SVG',
1745+
templateNamespace: 'SVG',
17451746
scope: {
17461747
linkurl: '@svgAnchor',
17471748
text: '@?'
@@ -1764,13 +1765,13 @@ describe('$compile', function() {
17641765
// and even there, the browser does not export MathML element constructors globally.
17651766
// So the test is slightly limited in what it does. But as browsers begin to
17661767
// implement MathML natively, this can be tightened up to be more meaningful.
1767-
it('should support MathML templates using directive.type=math', function() {
1768+
it('should support MathML templates using directive.templateNamespace=math', function() {
17681769
module(function() {
17691770
directive('pow', valueFn({
17701771
replace: true,
17711772
transclude: true,
17721773
templateUrl: 'template.html',
1773-
type: 'MATH',
1774+
templateNamespace: 'math',
17741775
scope: {
17751776
pow: '@pow',
17761777
},
@@ -1787,6 +1788,7 @@ describe('$compile', function() {
17871788
$rootScope.$digest();
17881789
var child = element.children().eq(0);
17891790
expect(nodeName_(child)).toMatch(/msup/i);
1791+
expect(child[0].constructor).toBe(window.Element);
17901792
});
17911793
});
17921794
});

0 commit comments

Comments
 (0)