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

Commit fd420c4

Browse files
petebacondarwincaitp
authored andcommittedJun 13, 2014
fix($compile): ensure transclude works at root of templateUrl
If a "replace" directive has an async template, which contains a transclusion directive at its root node, then outer transclusions were failing to be passed to this directive. An example would be uses of `ngIf` inside and outside the template. Collaborated with @caitp Closes #7183 Closes #7772
1 parent 1382d4e commit fd420c4

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed
 

‎src/ng/compile.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
17381738
});
17391739
afterTemplateChildLinkFn = compileNodes($compileNode[0].childNodes, childTranscludeFn);
17401740

1741-
17421741
while(linkQueue.length) {
17431742
var scope = linkQueue.shift(),
17441743
beforeTemplateLinkNode = linkQueue.shift(),
@@ -1775,13 +1774,17 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
17751774
});
17761775

17771776
return function delayedNodeLinkFn(ignoreChildLinkFn, scope, node, rootElement, boundTranscludeFn) {
1777+
var childBoundTranscludeFn = boundTranscludeFn;
17781778
if (linkQueue) {
17791779
linkQueue.push(scope);
17801780
linkQueue.push(node);
17811781
linkQueue.push(rootElement);
1782-
linkQueue.push(boundTranscludeFn);
1782+
linkQueue.push(childBoundTranscludeFn);
17831783
} else {
1784-
afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, node, rootElement, boundTranscludeFn);
1784+
if (afterTemplateNodeLinkFn.transcludeOnThisElement) {
1785+
childBoundTranscludeFn = createBoundTranscludeFn(scope, afterTemplateNodeLinkFn.transclude, boundTranscludeFn);
1786+
}
1787+
afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, node, rootElement, childBoundTranscludeFn);
17851788
}
17861789
};
17871790
}

‎test/ng/compileSpec.js

+51
Original file line numberDiff line numberDiff line change
@@ -4563,6 +4563,57 @@ describe('$compile', function() {
45634563

45644564
expect(element.text()).toBe('-->|x|');
45654565
}));
4566+
4567+
4568+
// See https://github.com/angular/angular.js/issues/7183
4569+
it("should pass transclusion through to template of a 'replace' directive", function() {
4570+
module(function() {
4571+
directive('transSync', function() {
4572+
return {
4573+
transclude: true,
4574+
link: function(scope, element, attr, ctrl, transclude) {
4575+
4576+
expect(transclude).toEqual(jasmine.any(Function));
4577+
4578+
transclude(function(child) { element.append(child); });
4579+
}
4580+
};
4581+
});
4582+
4583+
directive('trans', function($timeout) {
4584+
return {
4585+
transclude: true,
4586+
link: function(scope, element, attrs, ctrl, transclude) {
4587+
4588+
// We use timeout here to simulate how ng-if works
4589+
$timeout(function() {
4590+
transclude(function(child) { element.append(child); });
4591+
});
4592+
}
4593+
};
4594+
});
4595+
4596+
directive('replaceWithTemplate', function() {
4597+
return {
4598+
templateUrl: "template.html",
4599+
replace: true
4600+
};
4601+
});
4602+
});
4603+
4604+
inject(function($compile, $rootScope, $templateCache, $timeout) {
4605+
4606+
$templateCache.put('template.html', '<div trans-sync>Content To Be Transcluded</div>');
4607+
4608+
expect(function() {
4609+
element = $compile('<div><div trans><div replace-with-template></div></div></div>')($rootScope);
4610+
$timeout.flush();
4611+
}).not.toThrow();
4612+
4613+
expect(element.text()).toEqual('Content To Be Transcluded');
4614+
});
4615+
4616+
});
45664617
});
45674618

45684619

0 commit comments

Comments
 (0)
This repository has been archived.