Skip to content

Commit 925a6a5

Browse files
authored
fix(module:tabs): nzLinkRouter not work for the first time load (#9130)
1 parent f4c4e05 commit 925a6a5

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

components/tabs/tabset.component.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ describe('NzTabSet', () => {
107107
fixture.detectChanges();
108108
const component: NzTabSetComponent = fixture.debugElement.query(By.css('nz-tabset'))!.componentInstance;
109109

110-
// Set the index to be negative, expect first tab selected
110+
// Set the index to be negative, expect the first tab selected
111111
fixture.componentInstance.selectedIndex = -1;
112112
fixture.detectChanges();
113113
expect(component.nzSelectedIndex).toBe(0);
114114

115-
// Set the index beyond the size of the tabs, expect last tab selected
115+
// Set the index beyond the size of the tabs, expect the last tab selected
116116
fixture.componentInstance.selectedIndex = 3;
117117
fixture.detectChanges();
118118
expect(component.nzSelectedIndex).toBe(2);
@@ -510,7 +510,7 @@ describe('NzTabSet', () => {
510510
fixture.detectChanges();
511511
flush();
512512

513-
// Remove last tab while last tab is selected, expect next tab over to be selected
513+
// Remove last tab while last tab is selected, expect the next tab over to be selected
514514
fixture.componentInstance.tabs.pop();
515515
fixture.detectChanges();
516516
flush();

components/tabs/tabset.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,12 @@ export class NzTabSetComponent implements OnInit, AfterContentChecked, OnDestroy
308308
this.subscribeToTabLabels();
309309
this.subscribeToAllTabChanges();
310310

311-
// Subscribe to changes in the amount of tabs, in order to be
311+
// Subscribe to changes of the number of tabs, to be
312312
// able to re-render the content as new tabs are added or removed.
313313
this.tabsSubscription = this.tabs.changes.subscribe(() => {
314314
const indexToSelect = this.clampTabIndex(this.indexToSelect);
315315

316-
// Maintain the previously-selected tab if a new tab is added or removed and there is no
316+
// Maintain the previously selected tab if a new tab is added or removed, and there is no
317317
// explicit change that selects a different tab.
318318
if (indexToSelect === this.selectedIndex) {
319319
const tabs = this.tabs.toArray();
@@ -338,7 +338,7 @@ export class NzTabSetComponent implements OnInit, AfterContentChecked, OnDestroy
338338
// the amount of tabs changes before the actual change detection runs.
339339
const indexToSelect = (this.indexToSelect = this.clampTabIndex(this.indexToSelect));
340340

341-
// If there is a change in selected index, emit a change event. Should not trigger if
341+
// If there is a change in the selected index, emit a change event. Should not trigger if
342342
// the selected index has not yet been initialized.
343343
if (this.selectedIndex !== indexToSelect) {
344344
const isFirstRun = this.selectedIndex == null;
@@ -358,8 +358,8 @@ export class NzTabSetComponent implements OnInit, AfterContentChecked, OnDestroy
358358
});
359359
}
360360

361-
// Setup the position for each tab and optionally setup an origin on the next selected tab.
362-
this.tabs.forEach((tab: NzTabComponent, index: number) => {
361+
// Set up the position for each tab and optionally set up an origin on the next selected tab.
362+
this.tabs.forEach((tab, index) => {
363363
tab.position = index - indexToSelect;
364364

365365
// If there is already a selected tab, then set up an origin for the next selected tab
@@ -484,7 +484,7 @@ export class NzTabSetComponent implements OnInit, AfterContentChecked, OnDestroy
484484
throw new Error(`${PREFIX} you should import 'RouterModule' if you want to use 'nzLinkRouter'!`);
485485
}
486486
merge(this.router.events.pipe(filter(e => e instanceof NavigationEnd)), this.tabLinks.changes)
487-
.pipe(delay(0), takeUntil(this.destroy$))
487+
.pipe(startWith(true), delay(0), takeUntil(this.destroy$))
488488
.subscribe(() => {
489489
this.updateRouterActive();
490490
this.cdr.markForCheck();

0 commit comments

Comments
 (0)