Home >>Ngx Bootstrap Tutorial >Ngx Bootstrap Tabs
The ngx-bootstrap Tabs component provides a Tab component that is simple to use and highly configurable.
selector
Inputs
selector
Inputs
Outputs
As we're going to use a tab, app.module.ts must be updated to use TabsModule and TabsetConfig in the ngx-bootstrap Sortable chapter.
To use TabsModule and TabsetConfig, update app.module.ts.
app.module.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 { }
Update test.component.html to use the tabs component.
test.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>
Update test.component.ts for corresponding variables and methods.
test.component.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 { } }
Run the following command to start the angular server.
ng serve