Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tabset): Use the init state to determine if the nb-template should be loaded #3049

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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`);
}
}
}