From 9918b748be01266eb10db39d51b4d3098d54ab66 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 15 Mar 2012 22:18:06 -0700 Subject: fix(compiler): allow transclusion of root elements Fixed an issue where a directive that uses transclusion (such as ngRepeat) failed to link if it was declared on the root element of the compilation tree. (For example ngView or ngInclude including template where ngRepeat was the top most element). --- src/service/compiler.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/service/compiler.js') diff --git a/src/service/compiler.js b/src/service/compiler.js index 8aba28e4..6cbfc9d3 100644 --- a/src/service/compiler.js +++ b/src/service/compiler.js @@ -225,7 +225,10 @@ function $CompileProvider($provide) { //================================ function compile(templateElement, transcludeFn, maxPriority) { - templateElement = jqLite(templateElement); + if (!(templateElement instanceof jqLite)) { + // jquery always rewraps, where as we need to preserve the original selector so that we can modify it. + templateElement = jqLite(templateElement); + } // We can not compile top level text elements since text nodes can be merged and we will // not be able to attach scope data to them, so we will wrap them in forEach(templateElement, function(node, index){ @@ -488,7 +491,7 @@ function $CompileProvider($provide) { template = jqLite(templateNode); templateNode = (element = templateAttrs.$element = jqLite( ''))[0]; - template.replaceWith(templateNode); + replaceWith(rootElement, jqLite(template[0]), templateNode); childTranscludeFn = compile(template, transcludeFn, terminalPriority); } else { template = jqLite(JQLiteClone(templateNode)); -- cgit v1.2.3