我想以编程方式加载选项卡,因为我想使用 Angular 6 typescript 。目前,当我单击选项卡时它会加载。我想通过代码加载。这是我尝试过的示例代码,但它仍然在单击选项卡时加载。
<ngb-tabset #t="ngbTabset" [activeId]="activeIdString" (tabChange)="tabChangeEvent($event)">
<ngb-tab title="Workforce Plan-Headcount" id="wf1">
<ng-template ngbTabContent>
<app-workforce-plan-headcount></app-workforce-plan-headcount>
</ng-template>
</ngb-tab>
<ngb-tab title="Workforce Plan-Cost" id="wf2">
<ng-template ngbTabContent>
<app-workforce-plan-cost></app-workforce-plan-cost>
</ng-template>
</ngb-tab>
<ngb-tab title="Current Vacancies" id="wf3">
<ng-template ngbTabContent>
<app-current-vacancies></app-current-vacancies>
</ng-template>
</ngb-tab>
<ngb-tab title="Data Entry" id="wf4">
<ng-template ngbTabContent>
<app-data-entry></app-data-entry>
</ng-template>
</ngb-tab>
</ngb-tabset>
TS文件
activeIdString: string;
tabChangeEvent(evt: any) {
this.activeIdString = "wf3";
console.log(this.activeIdString);
}
我尝试了这段代码,它在第一次加载时加载第三个选项卡。然后它不会加载第三个选项卡。有没有以编程方式加载选项卡的最佳方法。
How do you get the selected tab from a bootstrap tabset in Angular4?
最佳答案
这对我来说是可行的解决方案,可能对其他人有用
<ngb-tabset #t="ngbTabset" (tabChange)="beforeChange($event)">
<ngb-tab title="Workforce Plan-Headcount" id="wf1">
<ng-template ngbTabContent>
<app-workforce-plan-headcount></app-workforce-plan-headcount>
</ng-template>
</ngb-tab>
<ngb-tab title="Workforce Plan-Cost" id="wf2">
<ng-template ngbTabContent>
<app-workforce-plan-cost></app-workforce-plan-cost>
</ng-template>
</ngb-tab>
<ngb-tab title="Current Vacancies" id="wf3">
<ng-template ngbTabContent>
<app-current-vacancies></app-current-vacancies>
</ng-template>
</ngb-tab>
<ngb-tab title="Data Entry" id="wf4">
<ng-template ngbTabContent>
<app-data-entry></app-data-entry>
</ng-template>
</ngb-tab>
</ngb-tabset>
component.ts 文件
public beforeChange($event: NgbTabChangeEvent) {
if (condition) {
// prevent from loading
$event.preventDefault();
}
else{
this.t.select($event.nextId);
}
}
关于javascript - 如何在 bootstrap ngb-tabset 的 Angular 6 中以编程方式加载选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53095895/