Muhammad Abdullah
Muhammad Abdullah

Reputation: 482

How to get the Main menu click value in nebular (Not the sub-menu click)

I am using the nebular menu in my project and I want the value of the main menu click not the submenu like,

Example:

menu 1 
  submenu 1
  submenu 2
menu 2
  submenu 1 
  submenu 2

I know there is a service method to get the submenu value but I want to get the value when the user clicks on for example "menu 1". On Main-menu click, it opens submenu and on that time I am not getting the value of the main menu

this.menuService.onItemClick().subscribe((event) => {
if (event.item.title === 'Log out') {
console.log('logout clicked');
}
});

and I know the reason why I am not getting in that. I am looking for another way to get what I want.

Upvotes: 1

Views: 1929

Answers (1)

Mikhail Gerasimov
Mikhail Gerasimov

Reputation: 36

items: any[] = [
    {
      title: 'home',
      link: '/',
      icon: 'alert-circle-outline',
      badge: {
        text: '30',
        status: 'primary',
      },
    },
    {
      icon: 'bell-outline',
      title: 'beell',
      link: 'notifications'
    },
    {
      icon: 'settings-outline',
      title: 'Settings',
      link: 'settings',
    },
    {
      icon: 'settings-outline',
      title: 'Settings Click',
      link: undefined,
      click: () => {
        alert('root');
      }
    }
  ];

In handler

this.menuService.onItemClick().subscribe((data) => {
      console.log(data);
      if (data.item.link === undefined) {
        const item = data.item as any;
        item.click();
      }
    });

Upvotes: 2

Related Questions