PerfectMemory / ngx-contextmenu

A context menu component for Angular
https://perfectmemory.github.io/ngx-contextmenu
MIT License
42 stars 12 forks source link

Refresh a contextmenu #16

Closed teet71 closed 1 year ago

teet71 commented 1 year ago

Hello!

I am trying to create a context menu that has a submenu which displays a list of options. The problem is that the list of options needs to be loaded async.

Current template for the submenu is the following:

<context-menu #addSubMenu [menuClass]="'add-sub-menu'"> <ng-template *ngIf="loadingContext" contextMenuItem [passive]="loadingContext">Loading <i class="loader ri-loader-2-line"></i></ng-template> <ng-template *ngFor="let option of contextMenuOptions | async" (execute)="onContextMenuItemSelect(option, $event.value)" contextMenuItem> {{ option.name }} </ng-template> <ng-template *ngIf="(contextMenuOptions | async)?.length === 0" [passive]="true" contextMenuItem> No options </ng-template> </context-menu>

The problem is that after the options are fetched, the submenu does not refresh automatically. It stays displaying the "loading..." item.

Perhaps this is more of a feature request, but if you know a quick solution to this issue, it would be much appreciated.

sroucheray commented 1 year ago

Hi @teet71 and thanks for submitting this issue.

I suspect this is a feature request as you said but if you could provide a stackblitz minimal example of the problem I could see if we have a workaround.

teet71 commented 1 year ago

Hello!

Thanks for taking the time to respond. I've already managed to create a workaround - the async function clicks the menu item that opens the submenu after a small timeout. This refreshes the display.