Skip to content

Commit 006041e

Browse files
Copilotrenemadsen
andcommitted
Fix ExpressionChangedAfterItHasBeenCheckedError in navigation menu component
Co-authored-by: renemadsen <[email protected]>
1 parent 5faf1e1 commit 006041e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

eform-client/src/app/modules/advanced/modules/navigation-menu/components/navigation-menu-page/navigation-menu-page.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnDestroy, OnInit, ViewChild, inject, AfterViewInit, ViewChildren, QueryList } from '@angular/core';
1+
import { Component, OnDestroy, OnInit, ViewChild, inject, AfterViewInit, ViewChildren, QueryList, ChangeDetectorRef } from '@angular/core';
22
import { CdkDragDrop, moveItemInArray, copyArrayItem, transferArrayItem, CdkDragMove, CdkDragRelease, CdkDropList, CdkDrag } from '@angular/cdk/drag-drop';
33
import {
44
NavigationMenuItemIndexedModel,
@@ -45,6 +45,7 @@ export class NavigationMenuPageComponent implements OnInit, OnDestroy, AfterView
4545
private overlay = inject(Overlay);
4646
private store = inject(Store);
4747
private dragDropService = inject(NavigationMenuDragDropService);
48+
private cdr = inject(ChangeDetectorRef);
4849

4950

5051
@ViewChild('resetMenuModal')
@@ -104,14 +105,16 @@ export class NavigationMenuPageComponent implements OnInit, OnDestroy, AfterView
104105
this.dropLists.forEach(dropList => {
105106
this.dragDropService.register(dropList);
106107
});
107-
108+
108109
// Subscribe to changes in drop lists (for dynamically added dropdowns)
109110
this.dropLists.changes.subscribe(() => {
110111
// Clear and re-register all drop lists when the list changes
111112
this.dragDropService.dropLists = [];
112113
this.dropLists?.forEach(dropList => {
113114
this.dragDropService.register(dropList);
114115
});
116+
// Trigger change detection to prevent ExpressionChangedAfterItHasBeenCheckedError
117+
this.cdr.detectChanges();
115118
});
116119
}
117120
}

0 commit comments

Comments
 (0)