@@ -1047,27 +1047,28 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1047
1047
maxPriority , ignoreDirective , previousCompileContext ) ;
1048
1048
compile . $$addScopeClass ( $compileNodes ) ;
1049
1049
var namespace = null ;
1050
- var namespaceAdaptedCompileNodes = $compileNodes ;
1051
- var lastCompileNode ;
1052
1050
return function publicLinkFn ( scope , cloneConnectFn , transcludeControllers , parentBoundTranscludeFn , futureParentElement ) {
1053
1051
assertArg ( scope , 'scope' ) ;
1054
1052
if ( ! namespace ) {
1055
1053
namespace = detectNamespaceForChildElements ( futureParentElement ) ;
1056
1054
}
1057
- if ( namespace !== 'html' && $compileNodes [ 0 ] !== lastCompileNode ) {
1058
- namespaceAdaptedCompileNodes = jqLite (
1055
+ var $linkNode ;
1056
+ if ( namespace !== 'html' ) {
1057
+ // When using a directive with replace:true and templateUrl the $compileNodes
1058
+ // (or a child element inside of them)
1059
+ // might change, so we need to recreate the namespace adapted compileNodes
1060
+ // for call to the link function.
1061
+ // Note: This will already clone the nodes...
1062
+ $linkNode = jqLite (
1059
1063
wrapTemplate ( namespace , jqLite ( '<div>' ) . append ( $compileNodes ) . html ( ) )
1060
1064
) ;
1065
+ } else if ( cloneConnectFn ) {
1066
+ // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
1067
+ // and sometimes changes the structure of the DOM.
1068
+ $linkNode = JQLitePrototype . clone . call ( $compileNodes ) ;
1069
+ } else {
1070
+ $linkNode = $compileNodes ;
1061
1071
}
1062
- // When using a directive with replace:true and templateUrl the $compileNodes
1063
- // might change, so we need to recreate the namespace adapted compileNodes.
1064
- lastCompileNode = $compileNodes [ 0 ] ;
1065
-
1066
- // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
1067
- // and sometimes changes the structure of the DOM.
1068
- var $linkNode = cloneConnectFn
1069
- ? JQLitePrototype . clone . call ( namespaceAdaptedCompileNodes ) // IMPORTANT!!!
1070
- : namespaceAdaptedCompileNodes ;
1071
1072
1072
1073
if ( transcludeControllers ) {
1073
1074
for ( var controllerName in transcludeControllers ) {
0 commit comments