Skip to content

Commit

Permalink
fix(tabset): Use the init state to determine if the nb-template shoul…
Browse files Browse the repository at this point in the history
…d be loaded

Use the existing state indication to prevent initial rendering of templates with he lazy directive
  • Loading branch information
Liberatys committed Apr 6, 2022
1 parent aedfbd3 commit 27ccb9e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/framework/theme/components/tabset/tabset.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { NbTabTitleDirective } from './tab-title.directive';
selector: 'nb-tab',
template: `
<ng-container
*ngIf="tabContentDirective; else projectedContent"
*ngIf="init && tabContentDirective; else projectedContent"
[ngTemplateOutlet]="tabContentDirective.templateRef"
></ng-container>
Expand Down
29 changes: 25 additions & 4 deletions src/playground/with-layout/tabset/tabset-test.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';

@Component({
selector: 'nb-tabset-test',
Expand Down Expand Up @@ -137,21 +139,40 @@ import { Router } from '@angular/router';
<nb-tab tabTitle="Tab #2">
<span>Content #2</span>
</nb-tab>
<nb-tab tabTitle="Tab #3" lazyLoad>
<span>Content #3</span>
<nb-tab tabTitle="Tab #3">
<ng-template nbTabContent>
{{ logTabLoad('3') }}
<span>Content #3</span>
</ng-template>
</nb-tab>
<nb-tab tabTitle="Tab #4" lazyLoad>
<span>Content #4</span>
<nb-tab tabTitle="Tab #4">
<ng-template nbTabContent>
{{ logTabLoad('4') }}
<span>Content #4</span>
</ng-template>
</nb-tab>
</nb-tabset>
`,
})
export class TabsetTestComponent {

constructor(private router: Router) {

}

changeTab($event: any) {
this.router.navigate(['tabset', 'tabset-test.component', $event.route]);
}

private tabs = new Map([
['3', false],
['4', false]
]);

public logTabLoad(tab: string) {
if(this.tabs.get(tab) === false) {
this.tabs.set(tab, true);
console.log(`The tab ${tab} is now loaded`);
}
}
}

0 comments on commit 27ccb9e

Please sign in to comment.