|
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'; |
2 | 2 | import { CdkDragDrop, moveItemInArray, copyArrayItem, transferArrayItem, CdkDragMove, CdkDragRelease, CdkDropList, CdkDrag } from '@angular/cdk/drag-drop'; |
3 | 3 | import { |
4 | 4 | NavigationMenuItemIndexedModel, |
@@ -45,6 +45,7 @@ export class NavigationMenuPageComponent implements OnInit, OnDestroy, AfterView |
45 | 45 | private overlay = inject(Overlay); |
46 | 46 | private store = inject(Store); |
47 | 47 | private dragDropService = inject(NavigationMenuDragDropService); |
| 48 | + private cdr = inject(ChangeDetectorRef); |
48 | 49 |
|
49 | 50 |
|
50 | 51 | @ViewChild('resetMenuModal') |
@@ -104,14 +105,16 @@ export class NavigationMenuPageComponent implements OnInit, OnDestroy, AfterView |
104 | 105 | this.dropLists.forEach(dropList => { |
105 | 106 | this.dragDropService.register(dropList); |
106 | 107 | }); |
107 | | - |
| 108 | + |
108 | 109 | // Subscribe to changes in drop lists (for dynamically added dropdowns) |
109 | 110 | this.dropLists.changes.subscribe(() => { |
110 | 111 | // Clear and re-register all drop lists when the list changes |
111 | 112 | this.dragDropService.dropLists = []; |
112 | 113 | this.dropLists?.forEach(dropList => { |
113 | 114 | this.dragDropService.register(dropList); |
114 | 115 | }); |
| 116 | + // Trigger change detection to prevent ExpressionChangedAfterItHasBeenCheckedError |
| 117 | + this.cdr.detectChanges(); |
115 | 118 | }); |
116 | 119 | } |
117 | 120 | } |
|
0 commit comments