Ngx-Bootstrap - แท็บ
องค์ประกอบแท็บ ngx-bootstrap ให้ส่วนประกอบแท็บที่ใช้งานง่ายและกำหนดค่าได้สูง
TabsetComponent
ตัวเลือก
tabset
อินพุต
justified - บูลีนหากแท็บจริงเติมคอนเทนเนอร์และมีความกว้างสม่ำเสมอ
type - สตริงคลาสบริบทการนำทาง: 'แท็บ' หรือ 'ยา'
vertical - ถ้าแท็บจริงจะวางในแนวตั้ง
TabDirective
ตัวเลือก
แท็บ [tab]
อินพุต
active - บูลีน, แท็บสลับสถานะที่ใช้งานอยู่
customClass- หากตั้งค่าสตริงจะถูกเพิ่มลงในแอตทริบิวต์คลาสของแท็บ รองรับหลายคลาส
disabled - บูลีนหากไม่สามารถเปิดใช้งานแท็บจริงได้
heading - สตริงข้อความส่วนหัวของแท็บ
id- สตริงรหัสแท็บ รหัสเดียวกันกับคำต่อท้าย '-link' จะถูกเพิ่มเข้าไปในสิ่งที่เกี่ยวข้อง
- element.
 removable - บูลีนหากสามารถถอดแท็บจริงได้ปุ่มเพิ่มเติมจะปรากฏขึ้น
เอาท์พุต
deselect - เริ่มทำงานเมื่อแท็บไม่ทำงาน $ event: Tab เท่ากับอินสแตนซ์ที่ยกเลิกการเลือกขององค์ประกอบ Tab
removed - เริ่มทำงานก่อนที่แท็บจะถูกลบออก $ event: Tab เท่ากับอินสแตนซ์ของแท็บที่ถูกลบ
selectTab - เริ่มทำงานเมื่อแท็บเริ่มทำงาน $ event: Tab เท่ากับอินสแตนซ์ที่เลือกขององค์ประกอบ Tab
ตัวอย่าง
ในขณะที่เรากำลังจะใช้ Tab เราต้องอัปเดต app.module.ts ที่ใช้ในngx-bootstrap Sortable chapter เพื่อใช้TabsModule และ TabsetConfig.
อัปเดต app.module.ts เพื่อใช้ TabsModule และ TabsetConfig
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 { } 
    อัปเดต test.component.html เพื่อใช้ส่วนประกอบแท็บ
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> 
    อัปเดต test.component.ts สำหรับตัวแปรและวิธีการที่เกี่ยวข้อง
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 {
   } 
} 
    สร้างและให้บริการ
รันคำสั่งต่อไปนี้เพื่อเริ่มเซิร์ฟเวอร์เชิงมุม
ng serve 
    เมื่อเซิร์ฟเวอร์เริ่มทำงาน เปิด http: // localhost: 4200 คลิกที่ปุ่ม Open modal และตรวจสอบผลลัพธ์ต่อไปนี้