Skip to content

Commit

Permalink
fix(docs): trigger change detection if tab updated (#1445)
Browse files Browse the repository at this point in the history
  • Loading branch information
yggg committed May 27, 2019
1 parent fb86847 commit 9679e3a
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions docs/app/documentation/page/page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import { Component, Inject, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Component, Inject, NgZone, OnDestroy, OnInit, ViewChild, AfterContentChecked } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute, Router } from '@angular/router';
import { filter, map, publishReplay, refCount, tap, takeWhile } from 'rxjs/operators';
Expand All @@ -17,11 +17,13 @@ import { NgdStructureService } from '../../@theme/services';
templateUrl: './page.component.html',
styleUrls: ['./page.component.scss'],
})
export class NgdPageComponent implements OnInit, OnDestroy {
export class NgdPageComponent implements OnInit, AfterContentChecked, OnDestroy {

currentItem;
private alive = true;

currentTabName: string = '';

@ViewChild(NgdTabbedBlockComponent) tabbedBlock: NgdTabbedBlockComponent;

constructor(@Inject(NB_WINDOW) private window,
Expand All @@ -42,6 +44,13 @@ export class NgdPageComponent implements OnInit, OnDestroy {
this.window.history.scrollRestoration = 'manual';
}

ngAfterContentChecked() {
const currentTabName = this.getCurrentTabName();
if (this.currentTabName !== currentTabName) {
Promise.resolve().then(() => this.currentTabName = currentTabName);
}
}

ngOnDestroy() {
this.alive = false;
}
Expand All @@ -66,4 +75,12 @@ export class NgdPageComponent implements OnInit, OnDestroy {
this.currentItem = item;
});
}

protected getCurrentTabName(): string {
if (this.tabbedBlock && this.tabbedBlock.currentTab) {
return this.tabbedBlock.currentTab.tab;
}

return '';
}
}

0 comments on commit 9679e3a

Please sign in to comment.