From ae8c61796da6670a62e76bc4308668a6856d2639 Mon Sep 17 00:00:00 2001 From: Stanislaus Date: Fri, 12 Feb 2016 15:00:22 -0800 Subject: [PATCH] fix(tabs): destroy cycle, closes #180 When tabset's view is destroyed, for example, the router change. There's an ```EXCEPTION: Attempt to use a dehydrated detector.``` throw on ng2-beta.6. --- components/tabs/tabset.component.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/tabs/tabset.component.ts b/components/tabs/tabset.component.ts index 531050e20d..40b7cd7fb7 100644 --- a/components/tabs/tabset.component.ts +++ b/components/tabs/tabset.component.ts @@ -64,6 +64,7 @@ export class Tabset implements OnInit { public tabs:Array = []; + private isDestroyed:boolean; private _vertical:boolean; private _justified:boolean; private _type:string; @@ -76,6 +77,10 @@ export class Tabset implements OnInit { this.type = this.type !== 'undefined' ? this.type : 'tabs'; } + ngOnDestroy() { + this.isDestroyed = true; + } + public addTab(tab:Tab) { this.tabs.push(tab); tab.active = this.tabs.length === 1 && tab.active !== false; @@ -83,7 +88,7 @@ export class Tabset implements OnInit { public removeTab(tab:Tab) { let index = this.tabs.indexOf(tab); - if (index === -1) { + if (index === -1 || this.isDestroyed) { return; } // Select a new tab if the tab to be removed is selected and not destroyed