@@ -955,26 +955,29 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
955
955
var compositeLinkFn =
956
956
compileNodes ( $compileNodes , transcludeFn , $compileNodes ,
957
957
maxPriority , ignoreDirective , previousCompileContext ) ;
958
-
959
958
compile . $$addScopeClass ( $compileNodes ) ;
960
-
959
+ var namespace = null ;
960
+ var namespaceAdaptedCompileNodes = $compileNodes ;
961
+ var lastCompileNode ;
961
962
return function publicLinkFn ( scope , cloneConnectFn , transcludeControllers , parentBoundTranscludeFn , futureParentElement ) {
962
- var namespace = null ;
963
963
assertArg ( scope , 'scope' ) ;
964
964
if ( ! namespace ) {
965
965
namespace = detectNamespaceForChildElements ( futureParentElement ) ;
966
- if ( namespace !== 'html' ) {
967
- $compileNodes = jqLite (
968
- wrapTemplate ( namespace , jqLite ( '<div>' ) . append ( $compileNodes ) . html ( ) )
969
- ) ;
970
- }
971
966
}
967
+ if ( namespace !== 'html' && $compileNodes [ 0 ] !== lastCompileNode ) {
968
+ namespaceAdaptedCompileNodes = jqLite (
969
+ wrapTemplate ( namespace , jqLite ( '<div>' ) . append ( $compileNodes ) . html ( ) )
970
+ ) ;
971
+ }
972
+ // When using a directive with replace:true and templateUrl the $compileNodes
973
+ // might change, so we need to recreate the namespace adapted compileNodes.
974
+ lastCompileNode = $compileNodes [ 0 ] ;
972
975
973
976
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
974
977
// and sometimes changes the structure of the DOM.
975
978
var $linkNode = cloneConnectFn
976
- ? JQLitePrototype . clone . call ( $compileNodes ) // IMPORTANT!!!
977
- : $compileNodes ;
979
+ ? JQLitePrototype . clone . call ( namespaceAdaptedCompileNodes ) // IMPORTANT!!!
980
+ : namespaceAdaptedCompileNodes ;
978
981
979
982
if ( transcludeControllers ) {
980
983
for ( var controllerName in transcludeControllers ) {
@@ -1940,7 +1943,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1940
1943
// it was cloned therefore we have to clone as well.
1941
1944
linkNode = jqLiteClone ( compileNode ) ;
1942
1945
}
1943
-
1944
1946
replaceWith ( linkRootElement , jqLite ( beforeTemplateLinkNode ) , linkNode ) ;
1945
1947
1946
1948
// Copy in CSS classes from original node
0 commit comments