@@ -979,7 +979,15 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
979
979
var lastCompileNode ;
980
980
return function publicLinkFn ( scope , cloneConnectFn , transcludeControllers , parentBoundTranscludeFn , futureParentElement ) {
981
981
assertArg ( scope , 'scope' ) ;
982
+ var shouldReplace = false ;
982
983
if ( ! namespace ) {
984
+ // If there's no namespace, and no futureParentElement, then we're probably compiling
985
+ // nodes in-place, so we should use the $compileNode's parent element in order to figure
986
+ // out the namespace.
987
+ if ( isUndefined ( futureParentElement ) && isUndefined ( cloneConnectFn ) ) {
988
+ if ( ( futureParentElement = $compileNodes . parent ( ) ) [ 0 ] )
989
+ shouldReplace = true ;
990
+ }
983
991
namespace = detectNamespaceForChildElements ( futureParentElement ) ;
984
992
}
985
993
if ( namespace !== 'html' && $compileNodes [ 0 ] !== lastCompileNode ) {
@@ -1008,7 +1016,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1008
1016
}
1009
1017
1010
1018
compile . $$addScopeInfo ( $linkNode , scope ) ;
1011
-
1019
+ // If we need to replace $compileNodes due to in-place compilation which resulted in
1020
+ // namespace adaptation, then append them to the parent node. (For whatever reason, the
1021
+ // $compileNodes are no longer children of the parent, so replacing is not possible)
1022
+ if ( shouldReplace && namespace !== 'html' && $linkNode . length === $compileNodes . length ) {
1023
+ for ( var i = 0 , ii = $linkNode . length ; i < ii ; ++ i ) {
1024
+ futureParentElement . append ( $linkNode ) ;
1025
+ }
1026
+ }
1012
1027
if ( cloneConnectFn ) cloneConnectFn ( $linkNode , scope ) ;
1013
1028
if ( compositeLinkFn ) compositeLinkFn ( scope , $linkNode , $linkNode , parentBoundTranscludeFn ) ;
1014
1029
return $linkNode ;
0 commit comments