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();
}
Firefox
Windows 10
Angular 6
Nebular 2.0.0-rc.9
onItemClick event raises up several times, any updates, fixes, workarounds there? Nebular version is 4.2.1
I am facing the same issue. Any update on this, please?
This problem is related to some error in your templates that can cause your constructor and ngOnInit to be called twice, as stated in this issue and a myriad of causes are stated in this stackoverflow thread.
To pinpoint the problem you can:
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
Most helpful comment
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 usingthis. test.unsubscribe();.It works for me. Have a nice day