Skip to content

Commit ab8cfff

Browse files
committed
fix(elements): Ensure ForOF out of bound row gets deleted before moving to bottom.
1 parent a86c8fd commit ab8cfff

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

projects/igniteui-angular/directives/src/directives/for-of/for_of.directive.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,12 +1061,17 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
10611061

10621062
for (let i = start; i < end && this.igxForOf[i] !== undefined; i++) {
10631063
const embView = this._embeddedViews.shift();
1064-
if (!embView.destroyed) {
1064+
if (embView && !embView.destroyed) {
10651065
this.scrollFocus(embView.rootNodes.find(node => node.nodeType === Node.ELEMENT_NODE)
10661066
|| embView.rootNodes[0].nextElementSibling);
10671067
const view = container.detach(0);
1068-
1068+
// embView and view both refer to the same collections
10691069
this.updateTemplateContext(embView.context, i);
1070+
1071+
// Because in Elements the whole parent div (containing data-index) gets removed (possibly due to being disconnected). In Angular it just gets moved.
1072+
// This ensures to update it with the new context and remove it first from DOM because of detach action before inserting it manually.
1073+
view.detectChanges();
1074+
10701075
container.insert(view);
10711076
this._embeddedViews.push(embView);
10721077
}
@@ -1081,12 +1086,15 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
10811086
const container = this.dc.instance._vcr as ViewContainerRef;
10821087
for (let i = prevIndex - 1; i >= this.state.startIndex && this.igxForOf[i] !== undefined; i--) {
10831088
const embView = this._embeddedViews.pop();
1084-
if (!embView.destroyed) {
1089+
if (embView && !embView.destroyed) {
10851090
this.scrollFocus(embView.rootNodes.find(node => node.nodeType === Node.ELEMENT_NODE)
10861091
|| embView.rootNodes[0].nextElementSibling);
1092+
// embView and view both refer to the same collections
10871093
const view = container.detach(container.length - 1);
10881094

10891095
this.updateTemplateContext(embView.context, i);
1096+
view.detectChanges();
1097+
10901098
container.insert(view, 0);
10911099
this._embeddedViews.unshift(embView);
10921100
}

0 commit comments

Comments
 (0)