Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($compile): render nested transclusion at the root of a template #8933

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
? JQLitePrototype.clone.call($compileNodes) // IMPORTANT!!!
: $compileNodes;

if ( $linkNode.length === 0 && parentBoundTranscludeFn ) {
$linkNode = parentBoundTranscludeFn(scope);
}

forEach(transcludeControllers, function(instance, name) {
$linkNode.data('$' + name + 'Controller', instance);
});
Expand Down
29 changes: 29 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4097,6 +4097,35 @@ describe('$compile', function() {
});


describe('collocated nested transcludes', function() {

beforeEach(module(function($compileProvider) {

$compileProvider.directive('inner', valueFn({
transclude: true,
template: '<div ng-transclude></div>'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to remove the ng-transclude directive and the test will still pass (transclusion still gets linked and appended) - just because there is no child element. That is wrong.

}));

$compileProvider.directive('outer', valueFn({
transclude: true,
template: '<a href="#"><div inner ng-transclude></div></a>'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try changing the template to <a href="#"><inner ng-transclude>xxx</inner></a> and the test will fail - suddenly xxx gets transcluded, instead of 'transcluded content'.

}));

}));


// Issue #8914
it('should render nested transclusion at the root of a template', inject(function($compile, $rootScope) {

element = $compile('<div><div outer>transcluded content</div></div>')($rootScope);
$rootScope.$digest();
expect(element.text()).toEqual('transcluded content');

}));

});


describe('nested transcludes', function() {

beforeEach(module(function($compileProvider) {
Expand Down