ng-bootstrap icon indicating copy to clipboard operation
ng-bootstrap copied to clipboard

close() should not trigger openChange, if invoked from ngOnDestroy

Open alexandis opened this issue 10 months ago • 0 comments

I am trying to reopen the menu which resides in a row of re-rendered grid. I use openChange event handler to keep track of row ID:

onContextMenuOpenChange(isOpen: boolean, row: MyData) {
    this.openedContextMenu = isOpen ? row.id : null;  
}

I could not make it work, because even though I did not change the menu visibility to false anywhere, it was somehow reset to false after reopening (and openChange handler does "explain" why - it just provides "true" or "false"). I later took a look and found out this:

close() {
    if (this._open) {
        this._open = false;
        this._resetContainer();
        this._positioning.destroy();
        this._zoneSubscription?.unsubscribe();
        this._destroyCloseHandlers$.next();
        this.openChange.emit(false); // it should not be invoked, if it called from ngOnDestroy
        this._changeDetector.markForCheck();
    }
}

ngOnDestroy() {
    this.close();
} 

alexandis avatar Apr 07 '24 18:04 alexandis