Skip to content

Commit 1dd206e

Browse files
fix($compile): revert allowing non-normalized element names in transclude map
Closes angular#13455
1 parent da5db4b commit 1dd206e

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

src/ng/compile.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,15 @@
480480
*
481481
* **Mult-slot transclusion** is declared by providing an object for the `transclude` property.
482482
*
483-
* This object is a map where the keys are the name of the slot to fill and the value is the element selector
484-
* used to match the HTML to the slot. Only element names are supported for matching. If the element selector
485-
* is prefixed with a `?` then that slot is optional.
483+
* This object is a map where the keys are the name of the slot to fill and the value is an element selector
484+
* used to match the HTML to the slot. The element selector should be in normalized form (e.g. `myElement`)
485+
* and will match the standard element variants (e.g. `my-element`, `my:element`, `data-my-element`, etc).
486486
*
487-
* For example, the transclude object `{ slotA: '?my-custom-element' }` maps `<my-custom-element>` elements to
487+
* For further information check out the guide on {@link guide/directive#matching-directives Matching Directives}
488+
*
489+
* If the element selector is prefixed with a `?` then that slot is optional.
490+
*
491+
* For example, the transclude object `{ slotA: '?myCustomElement' }` maps `<my-custom-element>` elements to
488492
* the `slotA` slot, which can be accessed via the `$transclude` function or via the {@link ngTransclude} directive.
489493
*
490494
* Slots that are not marked as optional (`?`) will trigger a compile time error if there are no matching elements
@@ -1910,7 +1914,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
19101914

19111915
// Add the matching elements into their slot
19121916
forEach($compileNode.contents(), function(node) {
1913-
var slotName = slotMap[nodeName_(node)];
1917+
var slotName = slotMap[directiveNormalize(nodeName_(node))];
19141918
if (slotName) {
19151919
filledSlots[slotName] = true;
19161920
slots[slotName] = slots[slotName] || [];

src/ng/directive/ngTransclude.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@
126126
* return {
127127
* restrict: 'E',
128128
* transclude: {
129-
* 'title': '?pane-title',
130-
* 'body': 'pane-body',
131-
* 'footer': '?pane-footer'
129+
* 'title': '?paneTitle',
130+
* 'body': 'paneBody',
131+
* 'footer': '?paneFooter'
132132
* },
133133
* template: '<div style="border: 1px solid black;">' +
134134
* '<div class="title" ng-transclude="title">Fallback Title</div>' +

test/ng/compileSpec.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -7941,27 +7941,33 @@ describe('$compile', function() {
79417941
});
79427942

79437943

7944-
it('should not normalize the element name', function() {
7944+
it('should match the normalized form of the element name', function() {
79457945
module(function() {
79467946
directive('foo', function() {
79477947
return {
79487948
restrict: 'E',
79497949
scope: {},
79507950
transclude: {
7951-
fooBarSlot: 'foo-bar'
7951+
fooBarSlot: 'fooBar',
7952+
mooKarSlot: 'mooKar'
79527953
},
79537954
template:
7954-
'<div class="other" ng-transclude="fooBarSlot"></div>'
7955+
'<div class="a" ng-transclude="fooBarSlot"></div>' +
7956+
'<div class="b" ng-transclude="mooKarSlot"></div>'
79557957
};
79567958
});
79577959
});
79587960
inject(function($rootScope, $compile) {
79597961
element = $compile(
79607962
'<foo>' +
7961-
'<foo-bar>baz</foo-bar>' +
7963+
'<foo-bar>bar1</foo-bar>' +
7964+
'<foo:bar>bar2</foo:bar>' +
7965+
'<moo-kar>baz1</moo-kar>' +
7966+
'<data-moo-kar>baz2</data-moo-kar>' +
79627967
'</foo>')($rootScope);
79637968
$rootScope.$apply();
7964-
expect(element.text()).toEqual('baz');
7969+
expect(element.children().eq(0).text()).toEqual('bar1bar2');
7970+
expect(element.children().eq(1).text()).toEqual('baz1baz2');
79657971
});
79667972
});
79677973

0 commit comments

Comments
 (0)