@@ -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 ( ! futureParentElement && ! cloneConnectFn ) {
988
+ if ( futureParentElement = $compileNodes [ 0 ] . parentNode )
989
+ shouldReplace = true ;
990
+ }
983
991
namespace = detectNamespaceForChildElements ( futureParentElement ) ;
984
992
}
985
993
if ( namespace !== 'html' && $compileNodes [ 0 ] !== lastCompileNode ) {
@@ -1008,7 +1016,11 @@ 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' )
1023
+ futureParentElement . append ( $linkNode ) ;
1012
1024
if ( cloneConnectFn ) cloneConnectFn ( $linkNode , scope ) ;
1013
1025
if ( compositeLinkFn ) compositeLinkFn ( scope , $linkNode , $linkNode , parentBoundTranscludeFn ) ;
1014
1026
return $linkNode ;
@@ -1017,7 +1029,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1017
1029
1018
1030
function detectNamespaceForChildElements ( parentElement ) {
1019
1031
// TODO: Make this detect MathML as well...
1020
- var node = parentElement && parentElement [ 0 ] ;
1032
+ var node = ( parentElement && parentElement [ 0 ] ) || parentElement ;
1021
1033
if ( ! node ) {
1022
1034
return 'html' ;
1023
1035
} else {
0 commit comments