- Ngx-Bootstrap 教程
- Ngx-Bootstrap - 主页
- Ngx-Bootstrap - 概述
- Ngx-Bootstrap - 环境设置
- Ngx-Bootstrap - 手风琴
- Ngx-Bootstrap - 警报
- Ngx-Bootstrap - 按钮
- Ngx-Bootstrap - 轮播
- Ngx-Bootstrap - 折叠
- Ngx-Bootstrap - DatePicker
- Ngx-Bootstrap - 下拉菜单
- Ngx-Bootstrap - 模态框
- Ngx-Bootstrap - 分页
- Ngx-Bootstrap - 弹出窗口
- Ngx-Bootstrap - 进度条
- Ngx-Bootstrap - 评级
- Ngx-Bootstrap - 可排序
- Ngx-Bootstrap - 选项卡
- Ngx-Bootstrap - 时间选择器
- Ngx-Bootstrap - 工具提示
- Ngx-Bootstrap - Typeahead
- Ngx-Bootstrap 有用资源
- Ngx-Bootstrap - 快速指南
- Ngx-Bootstrap - 有用的资源
- Ngx-Bootstrap - 讨论
Ngx-Bootstrap - 选项卡
ngx-bootstrap tabs 组件提供了一个易于使用且高度可配置的 Tab 组件。
选项卡组件
选择器
标签集
输入
justified - 布尔值,如果 true 选项卡填充容器并具有一致的宽度。
类型- 字符串,导航上下文类:'tabs' 或 'pills'。
垂直- 如果为 true 选项卡将垂直放置。
Tab指令
选择器
选项卡,[选项卡]
输入
active - 布尔值,选项卡活动状态切换。
customClass - 字符串,如果设置,将被添加到选项卡的类属性中。支持多个类。
已禁用- 布尔值,如果为 true,则无法激活选项卡。
header - 字符串,选项卡标题文本。
id - 字符串,选项卡 ID。相同的 id 带后缀“-link”将添加到相应的
- 元素。
可移动- 布尔值,如果 true 选项卡可移动,则会出现附加按钮。
输出
deselect - 当选项卡变为非活动状态时触发,$event:Tab 等于取消选择选项卡组件的实例。
已删除- 在删除选项卡之前触发,$event:Tab 等于已删除选项卡的实例。
selectTab - 当选项卡激活时触发,$event:Tab 等于选项卡组件的选定实例。
例子
由于我们要使用 Tab,我们必须更新ngx-bootstrap Sortable章节中使用的 app.module.ts 以使用TabsModule和TabsetConfig。
更新 app.module.ts 以使用 TabsModule 和 TabsetConfig。
应用程序模块.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { TestComponent } from './test/test.component';
import { AccordionModule } from 'ngx-bootstrap/accordion';
import { AlertModule,AlertConfig } from 'ngx-bootstrap/alert';
import { ButtonsModule } from 'ngx-bootstrap/buttons';
import { FormsModule } from '@angular/forms';
import { CarouselModule } from 'ngx-bootstrap/carousel';
import { CollapseModule } from 'ngx-bootstrap/collapse';
import { BsDatepickerModule, BsDatepickerConfig } from 'ngx-bootstrap/datepicker';
import { BsDropdownModule,BsDropdownConfig } from 'ngx-bootstrap/dropdown';
import { PaginationModule,PaginationConfig } from 'ngx-bootstrap/pagination';
import { PopoverModule, PopoverConfig } from 'ngx-bootstrap/popover';
import { ProgressbarModule,ProgressbarConfig } from 'ngx-bootstrap/progressbar';
import { RatingModule, RatingConfig } from 'ngx-bootstrap/rating';
import { SortableModule, DraggableItemService } from 'ngx-bootstrap/sortable';
import { TabsModule, TabsetConfig } from 'ngx-bootstrap/tabs';
@NgModule({
declarations: [
AppComponent,
TestComponent
],
imports: [
BrowserAnimationsModule,
BrowserModule,
AccordionModule,
AlertModule,
ButtonsModule,
FormsModule,
CarouselModule,
CollapseModule,
BsDatepickerModule.forRoot(),
BsDropdownModule,
ModalModule,
PaginationModule,
PopoverModule,
ProgressbarModule,
RatingModule,
SortableModule,
TabsModule
],
providers: [AlertConfig,
BsDatepickerConfig,
BsDropdownConfig,
BsModalService,
PaginationConfig,
ProgressbarConfig,
RatingConfig,
DraggableItemService,
TabsetConfig],
bootstrap: [AppComponent]
})
export class AppModule { }
更新 test.component.html 以使用选项卡组件。
测试.component.html
<tabset>
<tab heading="Home">Home</tab>
<tab *ngFor="let tabz of tabs"
[heading]="tabz.title"
[active]="tabz.active"
(selectTab)="tabz.active = true"
[disabled]="tabz.disabled">
{{tabz?.content}}
</tab>
</tabset>
更新 test.component.ts 中相应的变量和方法。
测试组件.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
tabs = [
{ title: 'First', content: 'First Tab Content' },
{ title: 'Second', content: 'Second Tab Content', active: true },
{ title: 'Third', content: 'Third Tab Content', removable: true },
{ title: 'Four', content: 'Fourth Tab Content', disabled: true }
];
constructor() {}
ngOnInit(): void {
}
}
构建和服务
运行以下命令启动角度服务器。
ng serve
服务器启动并运行后。打开http://localhost:4200。单击“打开模式”按钮并验证以下输出。
