From ab8cfffb913752314b23427b2ffb80afcddeaaaf Mon Sep 17 00:00:00 2001 From: skrustev Date: Thu, 16 Apr 2026 17:52:00 +0300 Subject: [PATCH] fix(elements): Ensure ForOF out of bound row gets deleted before moving to bottom. --- .../src/directives/for-of/for_of.directive.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/projects/igniteui-angular/directives/src/directives/for-of/for_of.directive.ts b/projects/igniteui-angular/directives/src/directives/for-of/for_of.directive.ts index 61ef7f970ee..591c083248e 100644 --- a/projects/igniteui-angular/directives/src/directives/for-of/for_of.directive.ts +++ b/projects/igniteui-angular/directives/src/directives/for-of/for_of.directive.ts @@ -1061,12 +1061,17 @@ export class IgxForOfDirective extends IgxForOfToken node.nodeType === Node.ELEMENT_NODE) || embView.rootNodes[0].nextElementSibling); const view = container.detach(0); - + // embView and view both refer to the same collections this.updateTemplateContext(embView.context, i); + + // Because in Elements the whole parent div (containing data-index) gets removed (possibly due to being disconnected). In Angular it just gets moved. + // This ensures to update it with the new context and remove it first from DOM because of detach action before inserting it manually. + view.detectChanges(); + container.insert(view); this._embeddedViews.push(embView); } @@ -1081,12 +1086,15 @@ export class IgxForOfDirective extends IgxForOfToken= this.state.startIndex && this.igxForOf[i] !== undefined; i--) { const embView = this._embeddedViews.pop(); - if (!embView.destroyed) { + if (embView && !embView.destroyed) { this.scrollFocus(embView.rootNodes.find(node => node.nodeType === Node.ELEMENT_NODE) || embView.rootNodes[0].nextElementSibling); + // embView and view both refer to the same collections const view = container.detach(container.length - 1); this.updateTemplateContext(embView.context, i); + view.detectChanges(); + container.insert(view, 0); this._embeddedViews.unshift(embView); }