diff --git a/packages/core/src/render3/view_engine_compatibility.ts b/packages/core/src/render3/view_engine_compatibility.ts index 623d2f663f..26834e538f 100644 --- a/packages/core/src/render3/view_engine_compatibility.ts +++ b/packages/core/src/render3/view_engine_compatibility.ts @@ -271,8 +271,12 @@ export function createContainerRef( throw new Error('Cannot move a destroyed View in a ViewContainer!'); } const index = this.indexOf(viewRef); - if (index !== -1) this.detach(index); - this.insert(viewRef, newIndex); + if (index === -1) { + this.insert(viewRef, newIndex); + } else if (index !== newIndex) { + this.detach(index); + this.insert(viewRef, newIndex); + } return viewRef; }