').append($compileNodes).html())
+ );
+ }
+ // 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($compileNodes) // IMPORTANT!!!
- : $compileNodes;
+ ? JQLitePrototype.clone.call(namespaceAdaptedCompileNodes) // IMPORTANT!!!
+ : namespaceAdaptedCompileNodes;
if (transcludeControllers) {
for (var controllerName in transcludeControllers) {
@@ -1940,7 +1943,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
// it was cloned therefore we have to clone as well.
linkNode = jqLiteClone(compileNode);
}
-
replaceWith(linkRootElement, jqLite(beforeTemplateLinkNode), linkNode);
// Copy in CSS classes from original node
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js
index 41808b2351a5..d628ba716dc7 100755
--- a/test/ng/compileSpec.js
+++ b/test/ng/compileSpec.js
@@ -289,6 +289,39 @@ describe('$compile', function() {
}));
+ it('should support directives with SVG templates and a slow url '+
+ 'that are stamped out later by a transcluding directive', function() {
+ module(function() {
+ directive('svgCircleUrl', valueFn({
+ replace: true,
+ templateUrl: 'template.html',
+ templateNamespace: 'SVG',
+ }));
+ });
+ inject(function($compile, $rootScope, $httpBackend) {
+ $httpBackend.expect('GET', 'template.html').respond('');
+ element = $compile('')($rootScope);
+
+ // initially the template is not yet loaded
+ $rootScope.$apply(function() {
+ $rootScope.list = [1];
+ });
+ expect(element.find('svg-circle-url').length).toBe(1);
+ expect(element.find('circle').length).toBe(0);
+
+ // template is loaded and replaces the existing nodes
+ $httpBackend.flush();
+ expect(element.find('svg-circle-url').length).toBe(0);
+ expect(element.find('circle').length).toBe(1);
+
+ // new entry should immediately use the loaded template
+ $rootScope.$apply(function() {
+ $rootScope.list.push(2);
+ });
+ expect(element.find('svg-circle-url').length).toBe(0);
+ expect(element.find('circle').length).toBe(2);
+ });
+ });
});