I have an Angular material menu with sub-menu panels. It's in a file manager app, and there is a context menu for the files, which has an option to "Move to" a folder:
I an trying to make clicking a middle level panel also close the entire menu (this is not the default behavior).
To do that, i wrote this function:
private handleClosingOptionsMenuWhenMovingFiles() {
this.actionsMenuOpened$.pipe(
untilComponentDestroyed(this)
).subscribe(() => {
this.documentsTabDetailsService.moveToFolderEvent$.pipe(
takeUntil(this.contextMenuTrigger.menuClosed),
).subscribe(
() => this.contextMenuTrigger.closeMenu(),
() => { },
() => console.log(' COMPLETED'));
});
}
It works great, but it's using ugly nested subscribes, and i can't figure out how to convert it to a single pipe with operators, and only one subscribe at the end.
The issue is that the actionsMenuOpened$ should still be subscribed to, because the user may open the menu again, but the inner stream of moveToFolderEvent$ should complete each time the menu is closed.
Any idea?