question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NbMenuService.onItemClick() calls even if not clicked after the first time

See original GitHub issue

Issue type

  • bug report
  • feature request
  • question about the decisions made in the repository

Issue description

Current behavior: “NbMenuService” component’s onItemClick event is called even though I don’t click to it, and unsubscribe on destroy.

Expected behavior: NbMenuService.onItemClick() only called on click.

Steps to reproduce:

I added this to header component in ngx-admin, and on logout route I call auth.logout(). I log in and redirect to dashboard. Then if I click logout, it redirects me to login page, everything works proper until now. But after logging out, if I login and redirect to dashboard again, it will call logout directly.

Related code:

test: Subscription;
ngOnInit() {
  this.test = this.menuService.onItemClick()
    .pipe(
             filter(({ tag }) => tag === 'my-context-menu'),
             map(({ item: { title } }) => title),
          ).subscribe(title => {
            if (title == 'Logout') {
              this.router.navigate(['/auth/logout']);
            }
        }
  );
}

ngOnDestroy() {
  test.unsubscribe();
}

Other information:

Firefox Windows 10 Angular 6 Nebular 2.0.0-rc.9

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

6reactions
DiegoDominguezSTXcommented, Jun 3, 2020

Hello! I have been trying to fix this issue when you implement the "onItemClick " event you should “unsubscribe”, the real problem of @mehmetalpsumer it’s a bad usage of ngOnDestroy method. Check out if the class is implemented in your class like: export class ExampleComponent implements OnInit, OnDestroy {} And you should call test.unsubscribe(); as a global variable using this. test.unsubscribe();.

It works for me. Have a nice day

0reactions
Akkiiiiiiicommented, Feb 20, 2021

@DiegoDominguezSTX you’r right we need to unsubscribe nbMenuService in ngOnDestroy() method . thank you so much @DiegoDominguezSTX

Read more comments on GitHub >

github_iconTop Results From Across the Web

NbMenuService.onItemClick() calls even if not clicked after ...
Current behavior: "NbMenuService" component's onItemClick event is called even though I don't click to it, and unsubscribe on destroy. Expected ...
Read more >
How to get the Main menu click value in nebular (Not ...
menuService.onItemClick().subscribe((event) => { if (event.item.
Read more >
nebular/theme/index.metadata.json
'chevron-left-outline' : 'chevron-right-outline'\" pack=\"nebular-essentials\"></nb-icon>\n </button>\n <button nbButton (click)=\"next.emit()\" ghost ...
Read more >
CHANGELOG.md · Gitee 极速下载/Nebular - Gitee.com
menu: The NbMenuService not reply the last click event. To update: if you use the knowledge that the last click event is replied...
Read more >
akveo/nebular release history - changelogs.md
menu: The NbMenuService not reply the last click event. To update: if you use the knowledge that the last click event is replied...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found