Skip to content

Commit

Permalink
fix(tabs): destroy cycle, closes #180
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
haolong7 authored and valorkin committed Feb 24, 2016
1 parent ec3d190 commit ae8c617
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion components/tabs/tabset.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class Tabset implements OnInit {

public tabs:Array<Tab> = [];

private isDestroyed:boolean;
private _vertical:boolean;
private _justified:boolean;
private _type:string;
Expand All @@ -76,14 +77,18 @@ 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;
}

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
Expand Down

0 comments on commit ae8c617

Please sign in to comment.