Skip to content

Commit

Permalink
fix(tabset): fix exception, when renders conditionally with *ngIf dir…
Browse files Browse the repository at this point in the history
…ective (#501)
  • Loading branch information
denStrigo authored and nnixaa committed Jun 21, 2018
1 parent 253c634 commit 946e68c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/framework/theme/components/tabset/tabset.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import { map, delay } from 'rxjs/operators';
import {
Component,
Input,
Expand All @@ -13,6 +14,7 @@ import {
QueryList,
AfterContentInit,
HostBinding,
ChangeDetectorRef,
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';

Expand Down Expand Up @@ -190,15 +192,24 @@ export class NbTabsetComponent implements AfterContentInit {
*/
@Output() changeTab = new EventEmitter<any>();

constructor(private route: ActivatedRoute) {
constructor(private route: ActivatedRoute,
private changeDetectorRef: ChangeDetectorRef) {
}

// TODO: refactoring this component, avoid change detection loop
ngAfterContentInit() {
this.route.params
.subscribe((params: any) => {
const activeTab = this.tabs.find(tab => this.routeParam ? tab.route === params[this.routeParam] : tab.active);
.pipe(
map(
(params: any) =>
this.tabs.find((tab) => this.routeParam ? tab.route === params[this.routeParam] : tab.active),
),
delay(0),
)
.subscribe((activeTab) => {
this.selectTab(activeTab || this.tabs.first);
});
this.changeDetectorRef.markForCheck();
});
}

// TODO: navigate to routeParam
Expand Down

0 comments on commit 946e68c

Please sign in to comment.