@@ -891,22 +891,26 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
891
891
maxPriority , ignoreDirective , previousCompileContext ) ;
892
892
safeAddClass ( $compileNodes , 'ng-scope' ) ;
893
893
var namespace = null ;
894
+ var namespaceAdaptedCompileNodes = $compileNodes ;
894
895
return function publicLinkFn ( scope , cloneConnectFn , transcludeControllers , parentBoundTranscludeFn , futureParentElement ) {
895
896
assertArg ( scope , 'scope' ) ;
896
897
if ( ! namespace ) {
897
898
namespace = detectNamespaceForChildElements ( futureParentElement ) ;
898
- if ( namespace !== 'html' ) {
899
- $compileNodes = jqLite (
900
- wrapTemplate ( namespace , jqLite ( '<div>' ) . append ( $compileNodes ) . html ( ) )
901
- ) ;
902
- }
899
+ }
900
+ if ( namespace !== 'html' && ! $compileNodes [ 0 ] [ '$$namespace' ] ) {
901
+ namespaceAdaptedCompileNodes = jqLite (
902
+ wrapTemplate ( namespace , jqLite ( '<div>' ) . append ( $compileNodes ) . html ( ) )
903
+ ) ;
904
+ // When using a directive with replace:true and templateUrl the $compileNodes
905
+ // might change, so we need to recreate the namespace adapted compileNodes.
906
+ $compileNodes [ 0 ] [ '$$namespace' ] = namespace ;
903
907
}
904
908
905
909
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
906
910
// and sometimes changes the structure of the DOM.
907
911
var $linkNode = cloneConnectFn
908
- ? JQLitePrototype . clone . call ( $compileNodes ) // IMPORTANT!!!
909
- : $compileNodes ;
912
+ ? JQLitePrototype . clone . call ( namespaceAdaptedCompileNodes ) // IMPORTANT!!!
913
+ : namespaceAdaptedCompileNodes ;
910
914
911
915
if ( transcludeControllers ) {
912
916
for ( var controllerName in transcludeControllers ) {
@@ -1888,7 +1892,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1888
1892
// it was cloned therefore we have to clone as well.
1889
1893
linkNode = jqLiteClone ( compileNode ) ;
1890
1894
}
1891
-
1892
1895
replaceWith ( linkRootElement , jqLite ( beforeTemplateLinkNode ) , linkNode ) ;
1893
1896
1894
1897
// Copy in CSS classes from original node
0 commit comments