Skip to content

Commit 1e4ebed

Browse files
test($compile): top level nested transcludes are passing down tree
If you have two directives that both expect to receive transcluded content the outer directive works but the inner directive never receives a transclusion function, only if the first transclude directive is not the first directive found in compilation. See angular#7240
1 parent 90335db commit 1e4ebed

File tree

1 file changed

+91
-1
lines changed

1 file changed

+91
-1
lines changed

test/ng/compileSpec.js

+91-1
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,59 @@ describe('$compile', function() {
14981498

14991499
iit('should pass the transcluded content through to ng-transclude', function() {
15001500

1501+
module(function($compileProvider) {
1502+
// This directive transcludes its contents and hopes to use the
1503+
// transcluded content in its template
1504+
$compileProvider.directive('transTest', valueFn({
1505+
templateUrl: 'transTestTemplate',
1506+
transclude: true
1507+
}));
1508+
});
1509+
1510+
inject(function($compile, $rootScope, $templateCache) {
1511+
// This is the template for the trans-test directive, it contains an
1512+
// ng-if, which also uses transclusion, which basically blocks the inner
1513+
// trans-test directive from receiving any transcluded content
1514+
$templateCache.put('transTestTemplate',
1515+
' <div ng-if="true">'+
1516+
' <div ng-transclude></div>'+
1517+
'</div>');
1518+
1519+
element = $compile('<div trans-test>transcluded content</div>')($rootScope);
1520+
1521+
// The ngTransclude:orphan error gets thrown when the digest occurs since this
1522+
// is when the ngTransclude directive tries to use the transcluded function.
1523+
$rootScope.$digest();
1524+
1525+
expect(element.text().trim()).toEqual('transcluded content');
1526+
});
1527+
});
1528+
1529+
1530+
iit('nested ngIfs should transclude correctly', function() {
1531+
1532+
module(function($compileProvider) {
1533+
// This directive does nothing except to put a directive in the compile
1534+
// element ancestors list between the root $compile node and the trans-test
1535+
// directives' element
1536+
$compileProvider.directive('noop', valueFn({}));
1537+
});
1538+
1539+
inject(function($compile, $rootScope) {
1540+
element = $compile('<div noop><div ng-if="true">outer<div ng-if="true">inner</div></div></div>')($rootScope);
1541+
1542+
// The ngTransclude:orphan error gets thrown when the digest occurs since this
1543+
// is when the ngTransclude directive tries to use the transcluded function.
1544+
$rootScope.$digest();
1545+
1546+
expect(element.text().trim()).toEqual('outerinner');
1547+
});
1548+
});
1549+
1550+
iit('should pass the transcluded content through to ng-transclude, ' +
1551+
'when not the highest directive' +
1552+
'and with external template', function() {
1553+
15011554
module(function($compileProvider) {
15021555
// This directive transcludes its contents and hopes to use the
15031556
// transcluded content in its template
@@ -1520,7 +1573,6 @@ describe('$compile', function() {
15201573
'<div noop>'+
15211574
' <div ng-if="true">'+
15221575
' <div ng-transclude></div>'+
1523-
' _this should be removed_' +
15241576
' </div>'+
15251577
'</div>');
15261578

@@ -1534,6 +1586,44 @@ describe('$compile', function() {
15341586
});
15351587
});
15361588

1589+
iit('should pass the transcluded content through to ng-transclude, ' +
1590+
'when not the highest directive' +
1591+
'and with inline template', function() {
1592+
1593+
module(function($compileProvider) {
1594+
// This directive transcludes its contents and hopes to use the
1595+
// transcluded content in its template
1596+
$compileProvider.directive('transTest', valueFn({
1597+
template:
1598+
// This is the template for the trans-test directive, it contains an
1599+
// ng-if, which also uses transclusion, which basically blocks the inner
1600+
// trans-test directive from receiving any transcluded content
1601+
'<div noop>'+
1602+
' <div ng-if="true">'+
1603+
' <div ng-transclude></div>'+
1604+
' </div>'+
1605+
'</div>',
1606+
transclude: true
1607+
}));
1608+
1609+
// This directive does nothing except to put a directive in the compile
1610+
// element ancestors list between the root $compile node and the trans-test
1611+
// directives' element
1612+
$compileProvider.directive('noop', valueFn({}));
1613+
});
1614+
1615+
inject(function($compile, $rootScope, $templateCache) {
1616+
1617+
element = $compile('<div trans-test>transcluded content</div>')($rootScope);
1618+
1619+
// The ngTransclude:orphan error gets thrown when the digest occurs since this
1620+
// is when the ngTransclude directive tries to use the transcluded function.
1621+
$rootScope.$digest();
1622+
1623+
expect(element.text().trim()).toEqual('transcluded content');
1624+
});
1625+
});
1626+
15371627

15381628
it("should fail if replacing and template doesn't have a single root element", function() {
15391629
module(function($exceptionHandlerProvider) {

0 commit comments

Comments
 (0)