我想使用ngbTabSet在卡片头和卡片内容中放置导航丸.但我不知道如何做到这一点.
以下是我尝试实现的示例(使用bootstrap.js)
<div class="card">
<div class="card-header">
<ul class="nav nav-pills" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">Contact</a>
</li>
</ul>
</div>
<div class="card-body">
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">Home</div>
<div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">Profile</div>
<div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">Contact</div>
</div>
</div>
</div>
这是我已经尝试过的(使用ng-bootstrap)
<div class="card">
<div class="card-header">
<ngb-tabset type="pills">
<ngb-tab title="Home">
<ng-template ngbTabContent>..</ng-template>
</ngb-tab>
</ngb-tabset>
</div>
</div>
使用模板ref时相同
<ng-template ngbTabContent>
<ng-container *ngTemplateOutlet="template_ref"></ng-container>
</ng-template>
我正在使用bootstrap 4.0,ng-bootstrap 2.0和Angular 5.2
任何人都知道如何使这个工作?
最佳答案 使用ng-bootstrap 2.0无法实现这一点. ngbTabset的模板不允许这样做.
我决定基于ngbTabset创建自己的tabset并自定义他们的模板.
这是我的组件
@Component({
selector: 'card-tabset',
templateUrl: './card-tabset.component.html',
})
export class CardTabsetComponent extends NgbTabset {
constructor(config: NgbTabsetConfig) {
super(config);
}
}
和模板
<div class="card">
<div class="card-header">
<ul [class]="'nav nav-' + type + (orientation == 'horizontal'? ' ' + justifyClass : ' flex-column')" role="tablist">
<li class="nav-item" *ngFor="let tab of tabs">
<a [id]="tab.id" class="nav-link" [class.active]="tab.id === activeId" [class.disabled]="tab.disabled" href (click)="!!select(tab.id)"
role="tab" [attr.tabindex]="(tab.disabled ? '-1': undefined)" [attr.aria-controls]="(!destroyOnHide || tab.id === activeId ? tab.id + '-panel' : null)"
[attr.aria-expanded]="tab.id === activeId" [attr.aria-disabled]="tab.disabled">
{{tab.title}}
<ng-template [ngTemplateOutlet]="tab.titleTpl?.templateRef"></ng-template>
</a>
</li>
</ul>
</div>
<div class="card-body">
<div class="tab-content">
<ng-template ngFor let-tab [ngForOf]="tabs">
<div class="tab-pane {{tab.id === activeId ? 'active' : null}}" *ngIf="!destroyOnHide || tab.id === activeId" role="tabpanel"
[attr.aria-labelledby]="tab.id" id="{{tab.id}}-panel" [attr.aria-expanded]="tab.id === activeId">
<ng-template [ngTemplateOutlet]="tab.contentTpl?.templateRef"></ng-template>
</div>
</ng-template>
</div>
</div>
</div>