Templarian / ui.bootstrap.contextMenu

AngularJS Bootstrap UI Context Menu
MIT License
259 stars 127 forks source link

Conditionally load the context menu #139

Open drichard1989 opened 6 years ago

drichard1989 commented 6 years ago

So, right now, there is an empty text attribute, but would it be possible for an attribute to be added in order to load a context menu at all? We are trying to if a variable if false, not load context-menu at all by using ng-attr, but with no luck. Maybe have context-menu-enabled and let a conditional be put in there to be evaluated and if false, not load it at all? That way we don't have it load and have 'empty ' as the only option that displays. Thanks!

zamb3zi commented 6 years ago

This used to work (see #11) but now we're getting the 'empty' menu when returning [] or undefined. I've had to work around this by modifying around lines 610 to only do the $broadcast and renderContextMenu if promisedMenu is truthey.

bartcorremans commented 3 years ago

For anyone who might come across this in the future: You can use the following hack to ensure that the menu never appears if it only contains the default 'empty' option.

this.$rootScope.$on('context-menu-opened', (event, args) => {
    if (!args.params.options.length) {
        // make sure to pass the event name below to the close-menu-on directive option
        this.$rootScope.$broadcast('close-context-menus');
    }
});