Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug dragSort => grid array #15

Open
DebuggerAK opened this issue Jul 15, 2021 · 1 comment
Open

bug dragSort => grid array #15

DebuggerAK opened this issue Jul 15, 2021 · 1 comment

Comments

@DebuggerAK
Copy link

DebuggerAK commented Jul 15, 2021

If I drag an item to another grid, the ngDestroy of MuuriGridItemDirective will have a wrong MuuriGridDirective:
ngOnDestroy() { this.tileGrid.removeItem(this.elRef); }

Current workaround:

 @ViewChildren(MuuriGridDirective) directives?: QueryList< MuuriGridDirective >;
  @ViewChildren(MuuriGridItemDirective) contentChildren?: QueryList< MuuriGridItemDirective >;
  private lastDragTargetGrid: Grid;
  private lastDragElementItem: HTMLElement | undefined;

grid.on('beforeSend',` ({ item, toGrid }) => {
      this.lastDragElementItem = item.getElement();
      this.lastDragTargetGrid = toGrid;
    });

grid.on('dragEnd', (item, event) => {
        const targetDirective = this.directives?.find(d => d.gridObject === this.lastDragTargetGrid);
        if (targetDirective) {
          const targetItemDirective = this.contentChildren?.find(child => child['elRef'].nativeElement === this.lastDragElementItem);
          if (targetItemDirective) {
            targetItemDirective['tileGrid'] = targetDirective;
          }
        }
    });

I change the internal tileGrid of MuuriGridItemDirective with the new target MuuriGridDirective.

The error occurs only when you leave oder change the page-routing. Only then is ngOnDestroy () called.

@DebuggerAK
Copy link
Author

Consequential failure:

core.js:6456 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'getItem' of null
TypeError: Cannot read property 'getItem' of null
    at MuuriGridDirective.removeItem (muuri-angular.js:50)
    at MuuriGridItemDirective.ngOnDestroy (muuri-angular.js:89)

If I insert an item in a grid further up in the hierarchy, it can no longer be deleted. No refresh of the MuuriGridDirectives? Angular will call ngOnDestroy before the new item is deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant