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

Commit f3539f3

Browse files
committed
fix($compile): use the correct namespace for transcluded svg elements
This fixes the case when a directive that uses `templateUrl` is used somewhere in the children of a transcluding directive like `ng-repeat`. Fixes #9344 Related to #8808 Closes #9415
1 parent 404b95f commit f3539f3

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/ng/compile.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -1150,27 +1150,28 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
11501150
maxPriority, ignoreDirective, previousCompileContext);
11511151
compile.$$addScopeClass($compileNodes);
11521152
var namespace = null;
1153-
var namespaceAdaptedCompileNodes = $compileNodes;
1154-
var lastCompileNode;
11551153
return function publicLinkFn(scope, cloneConnectFn, transcludeControllers, parentBoundTranscludeFn, futureParentElement){
11561154
assertArg(scope, 'scope');
11571155
if (!namespace) {
11581156
namespace = detectNamespaceForChildElements(futureParentElement);
11591157
}
1160-
if (namespace !== 'html' && $compileNodes[0] !== lastCompileNode) {
1161-
namespaceAdaptedCompileNodes = jqLite(
1158+
var $linkNode;
1159+
if (namespace !== 'html') {
1160+
// When using a directive with replace:true and templateUrl the $compileNodes
1161+
// (or a child element inside of them)
1162+
// might change, so we need to recreate the namespace adapted compileNodes
1163+
// for call to the link function.
1164+
// Note: This will already clone the nodes...
1165+
$linkNode = jqLite(
11621166
wrapTemplate(namespace, jqLite('<div>').append($compileNodes).html())
11631167
);
1168+
} else if (cloneConnectFn) {
1169+
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
1170+
// and sometimes changes the structure of the DOM.
1171+
$linkNode = JQLitePrototype.clone.call($compileNodes);
1172+
} else {
1173+
$linkNode = $compileNodes;
11641174
}
1165-
// When using a directive with replace:true and templateUrl the $compileNodes
1166-
// might change, so we need to recreate the namespace adapted compileNodes.
1167-
lastCompileNode = $compileNodes[0];
1168-
1169-
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
1170-
// and sometimes changes the structure of the DOM.
1171-
var $linkNode = cloneConnectFn
1172-
? JQLitePrototype.clone.call(namespaceAdaptedCompileNodes) // IMPORTANT!!!
1173-
: namespaceAdaptedCompileNodes;
11741175

11751176
if (transcludeControllers) {
11761177
for (var controllerName in transcludeControllers) {

test/ng/compileSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ describe('$compile', function() {
300300
});
301301
inject(function($compile, $rootScope, $httpBackend) {
302302
$httpBackend.expect('GET', 'template.html').respond('<circle></circle>');
303-
element = $compile('<svg><svg-circle-url ng-repeat="l in list"/></svg>')($rootScope);
303+
element = $compile('<svg><g ng-repeat="l in list"><svg-circle-url></svg-circle-url></g></svg>')($rootScope);
304304

305305
// initially the template is not yet loaded
306306
$rootScope.$apply(function() {

0 commit comments

Comments
 (0)