Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit ec59785

Browse files
committed
WIP: make broken tests pass, yeah
1 parent a8728eb commit ec59785

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/ng/compile.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -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 {

src/ng/directive/ngInclude.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,8 @@ var ngIncludeFillContentDirective = ['$compile',
267267
priority: -400,
268268
require: 'ngInclude',
269269
link: function(scope, $element, $attr, ctrl) {
270-
$element.empty();
271-
$compile(ctrl.template)(scope, function namespaceAdaptedClone(clone) {
272-
$element.append(clone);
273-
}, undefined, undefined, $element);
270+
$element.html(ctrl.template);
271+
$compile($element.contents())(scope);
274272
}
275273
};
276274
}];

test/ng/directive/ngIncludeSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ describe('ngInclude', function() {
490490
});
491491
});
492492

493-
ddescribe('ngInclude and transcludes', function() {
493+
describe('ngInclude and transcludes', function() {
494494
var element, directive;
495495

496496
beforeEach(module(function($compileProvider) {
@@ -592,7 +592,7 @@ ddescribe('ngInclude and transcludes', function() {
592592
});
593593

594594

595-
it('should correctly work with SVG content', function() {
595+
it('should construct SVG template elements with correct namespace', function() {
596596
if (!window.SVGRectElement) return;
597597
module(function() {
598598
directive('test', valueFn({

0 commit comments

Comments
 (0)