Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabs fire off activations during OnDestroy #696

Closed
slubowsky opened this issue Jul 8, 2016 · 12 comments
Closed

Tabs fire off activations during OnDestroy #696

slubowsky opened this issue Jul 8, 2016 · 12 comments
Assignees

Comments

@slubowsky
Copy link

slubowsky commented Jul 8, 2016

TabDirective.ngOnDestroy calls TabsetComponent.removeTab which checks if this.isDestroyed before continuing on and causing the next tab to be activated. The TabsetComponent component sets isDestroyed to true in ngOnDestroy. SO it appears that no events should be fired during compnent tear down.

Unfortunately it appears to me (using 2.0.0-rc.4) that OnDestroy is called in reverse order. First each tab then the tabset (and then my component which contains them)

I see the same behavior when putting breakpoints in the ng2-bootstrap demo page and watch things deconstruct from the tabs page when I click on another link.

See also #610 which sounds very similar

@valorkin
Copy link
Member

ok, got it
it will be hard one, but possible

@PEsteves8
Copy link

Any news on this? I need this to update the route on tab select, however when it's destroyed it navigates to the route defined in the (select) event handler.

Currently I'm using (click) on the heading span to do that (which is not ideal since it doesn't cover the entire tab heading section). Thanks :)

@sasapet
Copy link

sasapet commented Sep 2, 2016

I do need this fixed too; I have the same issue as PEsteves8.

@xwb1989
Copy link

xwb1989 commented Sep 2, 2016

Seeing the same issue. Would like to see it fixed.

@yippeeH
Copy link

yippeeH commented Nov 2, 2016

Any update on this? Having the same issue and hope it gets fixed soon.

@ipassynk
Copy link

This is the workaround that works for me. I use tab with (select) event to navigate between tabs using angular route.

    this.routeEvents$ = this.router.events
      .filter(event => event instanceof NavigationStart).subscribe(() => {
        this.isNavigation = true;
      });

  ngOnDestroy() {
    this.routeEvents$.unsubscribe();
  }

  selectTab(route) {
    if (!this.isNavigation) {
      let link = [`${route}`];
      this.router.navigate(link);
    }
  }

@hgoebl
Copy link

hgoebl commented Dec 1, 2016

@ipassynk do you set this.isNavigation to false somewhere? Or is it not necessary?

@ipassynk
Copy link

ipassynk commented Dec 1, 2016

yes, it is false on init. As soon as a router navigation started I do not want to receive 'select' event from tabs component and isNavigation flag does the trick for me.

@sasapet
Copy link

sasapet commented Dec 2, 2016

My solution: I changed the source node_modules\ng2-bootstrap\components\tabs\tabset.component.js,
by commenting line 70:
// this.tabs[newActiveIndex].active = true;

This might affect, thought, cases where you dynamically add/remove tabs, but it worked fine for me.

@xwb1989
Copy link

xwb1989 commented Dec 22, 2016

Found a simple fix:

import { TabDirective } from 'ng2-bootstrap';
TabDirective.prototype.ngOnDestroy = function () {
  /** 
   * We don't need to remove the tab itself from tabset during destroy because:
   * 1. If the destroy is triggered by closing the tab, the tab would have been already removed from the tabset
   * 2. If the destroy is triggered by switching to another route, the whole tabset will also be destroyed as well,
   *    therefore, there is no need to do the removal here.
   */
  // this.tabset.removeTab(this);
};

Not sure whether this would break other stuff, but it works for me.

@valorkin
Copy link
Member

@xwb1989 simple and good solution, let's try

@xwb1989
Copy link

xwb1989 commented Dec 22, 2016

Hope this can go into next release, then I can remove this hack patch from my code 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants