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

fix($compile): use the correct namespace for transcluded svg elements #9415

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 14 additions & 13 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
@@ -1047,27 +1047,28 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
maxPriority, ignoreDirective, previousCompileContext);
compile.$$addScopeClass($compileNodes);
var namespace = null;
var namespaceAdaptedCompileNodes = $compileNodes;
var lastCompileNode;
return function publicLinkFn(scope, cloneConnectFn, transcludeControllers, parentBoundTranscludeFn, futureParentElement){
assertArg(scope, 'scope');
if (!namespace) {
namespace = detectNamespaceForChildElements(futureParentElement);
}
if (namespace !== 'html' && $compileNodes[0] !== lastCompileNode) {
namespaceAdaptedCompileNodes = jqLite(
var $linkNode;
if (namespace !== 'html') {
// When using a directive with replace:true and templateUrl the $compileNodes
// (or a child element inside of them)
// might change, so we need to recreate the namespace adapted compileNodes
// for call to the link function.
// Note: This will already clone the nodes...
$linkNode = jqLite(
wrapTemplate(namespace, jqLite('<div>').append($compileNodes).html())
);
} else if (cloneConnectFn) {
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
// and sometimes changes the structure of the DOM.
$linkNode = JQLitePrototype.clone.call($compileNodes);
} else {
$linkNode = $compileNodes;
}
// When using a directive with replace:true and templateUrl the $compileNodes
// might change, so we need to recreate the namespace adapted compileNodes.
lastCompileNode = $compileNodes[0];

// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
// and sometimes changes the structure of the DOM.
var $linkNode = cloneConnectFn
? JQLitePrototype.clone.call(namespaceAdaptedCompileNodes) // IMPORTANT!!!
: namespaceAdaptedCompileNodes;

if (transcludeControllers) {
for (var controllerName in transcludeControllers) {
2 changes: 1 addition & 1 deletion test/ng/compileSpec.js
Original file line number Diff line number Diff line change
@@ -300,7 +300,7 @@ describe('$compile', function() {
});
inject(function($compile, $rootScope, $httpBackend) {
$httpBackend.expect('GET', 'template.html').respond('<circle></circle>');
element = $compile('<svg><svg-circle-url ng-repeat="l in list"/></svg>')($rootScope);
element = $compile('<svg><g ng-repeat="l in list"><svg-circle-url></svg-circle-url></g></svg>')($rootScope);

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