Ngx-Bootstrap - Schede

Il componente ngx-bootstrap tabs fornisce un componente Tab facile da usare e altamente configurabile.

TabsetComponent

selettore

  • tabset

Ingressi

  • justified - booleano, se le tabulazioni vere riempiono il contenitore e hanno una larghezza costante.

  • type - stringa, classe del contesto di navigazione: "schede" o "pillole".

  • vertical - se le schede vere verranno posizionate verticalmente.

TabDirective

selettore

  • tab, [tab]

Ingressi

  • active - booleano, attiva / disattiva lo stato della scheda.

  • customClass- stringa, se impostata, verrà aggiunta all'attributo class della scheda. Sono supportate più classi.

  • disabled - booleano, se la scheda true non può essere attivata.

  • heading - stringa, testo dell'intestazione della tabulazione.

  • id- stringa, tab id. Lo stesso ID con suffisso "-link" verrà aggiunto al corrispondente

  • element.

  • removable - booleano, se la scheda vera può essere rimovibile, verrà visualizzato un pulsante aggiuntivo.

Uscite

  • deselect - attivato quando la scheda è diventata inattiva, $ event: Tab è uguale all'istanza deselezionata del componente Tab.

  • removed - attivato prima che la scheda venga rimossa, $ event: la scheda è uguale all'istanza della scheda rimossa.

  • selectTab - attivato quando la scheda è diventata attiva, $ event: Tab è uguale all'istanza selezionata del componente Tab.

Esempio

Dato che useremo una scheda, dobbiamo aggiornare app.module.ts usato nel capitolo ordinabile ngx-bootstrap da usareTabsModule e TabsetConfig.

Aggiorna app.module.ts per utilizzare TabsModule e 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 { }

Aggiorna test.component.html per utilizzare il componente schede.

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>

Aggiorna test.component.ts per le variabili e i metodi corrispondenti.

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 {
   } 
}

Costruisci e servi

Eseguire il seguente comando per avviare il server angolare.

ng serve

Una volta che il server è attivo e funzionante. Apri http: // localhost: 4200. Fare clic sul pulsante modale Apri e verificare il seguente output.