@@ -1150,27 +1150,28 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1150
1150
maxPriority , ignoreDirective , previousCompileContext ) ;
1151
1151
compile . $$addScopeClass ( $compileNodes ) ;
1152
1152
var namespace = null ;
1153
- var namespaceAdaptedCompileNodes = $compileNodes ;
1154
- var lastCompileNode ;
1155
1153
return function publicLinkFn ( scope , cloneConnectFn , transcludeControllers , parentBoundTranscludeFn , futureParentElement ) {
1156
1154
assertArg ( scope , 'scope' ) ;
1157
1155
if ( ! namespace ) {
1158
1156
namespace = detectNamespaceForChildElements ( futureParentElement ) ;
1159
1157
}
1160
- if ( namespace !== 'html' && $compileNodes [ 0 ] !== lastCompileNode ) {
1161
- namespaceAdaptedCompileNodes = jqLite (
1158
+ var $linkNode ;
1159
+ if ( namespace !== 'html' ) {
1160
+ // When using a directive with replace:true and templateUrl the $compileNodes
1161
+ // (or a child element inside of them)
1162
+ // might change, so we need to recreate the namespace adapted compileNodes
1163
+ // for call to the link function.
1164
+ // Note: This will already clone the nodes...
1165
+ $linkNode = jqLite (
1162
1166
wrapTemplate ( namespace , jqLite ( '<div>' ) . append ( $compileNodes ) . html ( ) )
1163
1167
) ;
1168
+ } else if ( cloneConnectFn ) {
1169
+ // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
1170
+ // and sometimes changes the structure of the DOM.
1171
+ $linkNode = JQLitePrototype . clone . call ( $compileNodes ) ;
1172
+ } else {
1173
+ $linkNode = $compileNodes ;
1164
1174
}
1165
- // When using a directive with replace:true and templateUrl the $compileNodes
1166
- // might change, so we need to recreate the namespace adapted compileNodes.
1167
- lastCompileNode = $compileNodes [ 0 ] ;
1168
-
1169
- // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
1170
- // and sometimes changes the structure of the DOM.
1171
- var $linkNode = cloneConnectFn
1172
- ? JQLitePrototype . clone . call ( namespaceAdaptedCompileNodes ) // IMPORTANT!!!
1173
- : namespaceAdaptedCompileNodes ;
1174
1175
1175
1176
if ( transcludeControllers ) {
1176
1177
for ( var controllerName in transcludeControllers ) {
0 commit comments