From edcb34dc9f1fb0778534e16940d32a4b102d990f Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Wed, 9 Dec 2015 14:44:18 -0800 Subject: [PATCH] fix(dom_renderer): moveNodeAfterSiblings should not detach the reference node Fixes #5077 Closes #5759 --- modules/angular2/src/platform/dom/dom_renderer.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/angular2/src/platform/dom/dom_renderer.ts b/modules/angular2/src/platform/dom/dom_renderer.ts index b2c2e99c81..17f3040888 100644 --- a/modules/angular2/src/platform/dom/dom_renderer.ts +++ b/modules/angular2/src/platform/dom/dom_renderer.ts @@ -365,11 +365,18 @@ function resolveInternalDomFragment(fragmentRef: RenderFragmentRef): Node[] { } function moveNodesAfterSibling(sibling, nodes) { - if (nodes.length > 0 && isPresent(DOM.parentElement(sibling))) { - for (var i = 0; i < nodes.length; i++) { - DOM.insertBefore(sibling, nodes[i]); + var parent = DOM.parentElement(sibling); + if (nodes.length > 0 && isPresent(parent)) { + var nextSibling = DOM.nextSibling(sibling); + if (isPresent(nextSibling)) { + for (var i = 0; i < nodes.length; i++) { + DOM.insertBefore(nextSibling, nodes[i]); + } + } else { + for (var i = 0; i < nodes.length; i++) { + DOM.appendChild(parent, nodes[i]); + } } - DOM.insertBefore(nodes[0], sibling); } }