@@ -979,7 +979,15 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
979979 var lastCompileNode ;
980980 return function publicLinkFn ( scope , cloneConnectFn , transcludeControllers , parentBoundTranscludeFn , futureParentElement ) {
981981 assertArg ( scope , 'scope' ) ;
982+ var shouldReplace = false ;
982983 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 ( ! futureParentElement && ! cloneConnectFn ) {
988+ if ( futureParentElement = $compileNodes [ 0 ] . parentNode )
989+ shouldReplace = true ;
990+ }
983991 namespace = detectNamespaceForChildElements ( futureParentElement ) ;
984992 }
985993 if ( namespace !== 'html' && $compileNodes [ 0 ] !== lastCompileNode ) {
@@ -1008,7 +1016,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
10081016 }
10091017
10101018 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' )
1023+ futureParentElement . append ( $linkNode ) ;
10121024 if ( cloneConnectFn ) cloneConnectFn ( $linkNode , scope ) ;
10131025 if ( compositeLinkFn ) compositeLinkFn ( scope , $linkNode , $linkNode , parentBoundTranscludeFn ) ;
10141026 return $linkNode ;
@@ -1017,7 +1029,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
10171029
10181030 function detectNamespaceForChildElements ( parentElement ) {
10191031 // TODO: Make this detect MathML as well...
1020- var node = parentElement && parentElement [ 0 ] ;
1032+ var node = ( parentElement && parentElement [ 0 ] ) || parentElement ;
10211033 if ( ! node ) {
10221034 return 'html' ;
10231035 } else {
0 commit comments