|
1 | | -import { Component, OnDestroy, OnInit, ViewChild, inject, AfterViewInit, ViewChildren, QueryList, ChangeDetectorRef } from '@angular/core'; |
| 1 | +import { Component, OnDestroy, OnInit, ViewChild, inject, AfterViewInit, ViewChildren, QueryList } 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,7 +45,6 @@ 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); |
49 | 48 |
|
50 | 49 |
|
51 | 50 | @ViewChild('resetMenuModal') |
@@ -108,13 +107,15 @@ export class NavigationMenuPageComponent implements OnInit, OnDestroy, AfterView |
108 | 107 |
|
109 | 108 | // Subscribe to changes in drop lists (for dynamically added dropdowns) |
110 | 109 | this.dropLists.changes.subscribe(() => { |
111 | | - // Clear and re-register all drop lists when the list changes |
112 | | - this.dragDropService.dropLists = []; |
113 | | - this.dropLists?.forEach(dropList => { |
114 | | - this.dragDropService.register(dropList); |
| 110 | + // Use setTimeout to defer the update to avoid ExpressionChangedAfterItHasBeenCheckedError |
| 111 | + // This ensures the update happens after the current change detection cycle |
| 112 | + setTimeout(() => { |
| 113 | + // Clear and re-register all drop lists when the list changes |
| 114 | + this.dragDropService.dropLists = []; |
| 115 | + this.dropLists?.forEach(dropList => { |
| 116 | + this.dragDropService.register(dropList); |
| 117 | + }); |
115 | 118 | }); |
116 | | - // Trigger change detection to prevent ExpressionChangedAfterItHasBeenCheckedError |
117 | | - this.cdr.detectChanges(); |
118 | 119 | }); |
119 | 120 | } |
120 | 121 | } |
|
0 commit comments