Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d7639e0

Browse files
committedNov 25, 2015
fix(ngTransclude): fix case where ngTransclude attribute value equals its key
Some preprocessors such as Jade will automatically provide a value for an attribute rather than leave it empty. E.g. `<div ng-transclude="ng-transclude">`. In these situations we still want to use the default transclusion slot. Closes angular#12934
1 parent b2a937d commit d7639e0

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed
 

‎src/ng/directive/ngTransclude.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*
1616
* @element ANY
1717
*
18-
* @param {string} ngTransclude|ngTranscludeSlot the name of the slot to insert at this point. If this is not provided or empty then
19-
* the default slot is used.
18+
* @param {string} ngTransclude|ngTranscludeSlot the name of the slot to insert at this point. If this is not provided, is empty
19+
* or its value is the same as the name of the attribute then the default slot is used.
2020
*
2121
* @example
2222
* ### Default transclusion
@@ -113,6 +113,12 @@ var ngTranscludeDirective = ngDirective({
113113
restrict: 'EAC',
114114
link: function($scope, $element, $attrs, controller, $transclude) {
115115

116+
if ($attrs.ngTransclude === $attrs.$attr.ngTransclude) {
117+
// If the attribute is of the form: `ng-transclude="ng-transclude"`
118+
// then treat it like the default
119+
$attrs.ngTransclude = '';
120+
}
121+
116122
function ngTranscludeCloneAttachFn(clone) {
117123
$element.empty();
118124
$element.append(clone);

‎test/ng/compileSpec.js

+34
Original file line numberDiff line numberDiff line change
@@ -7680,6 +7680,40 @@ describe('$compile', function() {
76807680
});
76817681
});
76827682

7683+
it('should use the default transclusion slot if the ng-transclude attribute has the same value as its key', function() {
7684+
module(function() {
7685+
directive('minionComponent', function() {
7686+
return {
7687+
restrict: 'E',
7688+
scope: {},
7689+
transclude: {},
7690+
template:
7691+
'<div class="a" ng-transclude="ng-transclude"></div>' +
7692+
'<div class="b" ng:transclude="ng:transclude"></div>' +
7693+
'<div class="c" data-ng-transclude="data-ng-transclude"></div>'
7694+
};
7695+
});
7696+
});
7697+
inject(function($rootScope, $compile) {
7698+
element = $compile(
7699+
'<minion-component>' +
7700+
'<span>stuart</span>' +
7701+
'<span>bob</span>' +
7702+
'<span>kevin</span>' +
7703+
'</minion-component>')($rootScope);
7704+
$rootScope.$apply();
7705+
var a = element.children().eq(0);
7706+
var b = element.children().eq(1);
7707+
var c = element.children().eq(2);
7708+
expect(a).toHaveClass('a');
7709+
expect(b).toHaveClass('b');
7710+
expect(c).toHaveClass('c');
7711+
expect(a.text()).toEqual('stuartbobkevin');
7712+
expect(b.text()).toEqual('stuartbobkevin');
7713+
expect(c.text()).toEqual('stuartbobkevin');
7714+
});
7715+
});
7716+
76837717
it('should transclude elements to an `ng-transclude` with a matching transclusion slot name', function() {
76847718
module(function() {
76857719
directive('minionComponent', function() {

0 commit comments

Comments
 (0)
Please sign in to comment.