- Ngx-Bootstrap 教程
- Ngx-Bootstrap - 首頁
- Ngx-Bootstrap - 概述
- Ngx-Bootstrap - 環境設定
- Ngx-Bootstrap - 手風琴
- Ngx-Bootstrap - 警報
- Ngx-Bootstrap - 按鈕
- Ngx-Bootstrap - 走馬燈
- Ngx-Bootstrap - 摺疊
- Ngx-Bootstrap - 日期選擇器
- Ngx-Bootstrap - 下拉選單
- Ngx-Bootstrap - 模態框
- Ngx-Bootstrap - 分頁
- Ngx-Bootstrap - 氣泡提示
- Ngx-Bootstrap - 進度條
- Ngx-Bootstrap - 評分
- Ngx-Bootstrap - 可排序
- Ngx-Bootstrap - 標籤頁
- Ngx-Bootstrap - 時間選擇器
- Ngx-Bootstrap - 工具提示
- Ngx-Bootstrap - 自動完成
- Ngx-Bootstrap 有用資源
- Ngx-Bootstrap - 快速指南
- Ngx-Bootstrap - 有用資源
- Ngx-Bootstrap - 討論
Ngx-Bootstrap - 分頁
ngx-bootstrap 分頁元件為您的網站或元件提供分頁連結或分頁器元件。
PaginationComponent
選擇器
分頁
輸入
align − 布林值,如果為真,則將每個連結對齊到分頁器的兩側
boundaryLinks − 布林值,如果為假,則第一個和最後一個按鈕將隱藏
customFirstTemplate − TemplateRef<PaginationLinkContext>,第一個連結的自定義模板
customLastTemplate − TemplateRef<PaginationLinkContext>,最後一個連結的自定義模板
customNextTemplate − TemplateRef<PaginationLinkContext>,下一個連結的自定義模板
customPageTemplate − TemplateRef<PaginationLinkContext>,頁面連結的自定義模板
customPreviousTemplate − TemplateRef<PaginationLinkContext>,上一個連結的自定義模板
directionLinks − 布林值,如果為假,則上一個和下一個按鈕將隱藏
disabled − 布林值,如果為真,則分頁元件將被停用
firstText − 布林值,第一個按鈕文字
itemsPerPage − 數字,每頁最大專案數。如果值小於 1,則將在一個頁面上顯示所有專案
lastText − 字串,最後一個按鈕文字
maxSize − 數字,分頁器中頁面連結的數量限制
nextText − 字串,下一個按鈕文字
pageBtnClass − 字串,向<li>新增類
previousText − 字串,上一個按鈕文字
rotate − 布林值,如果為真,則當前頁面將在頁面列表的中間
totalItems − 數字,所有頁面中專案的總數
輸出
numPages − 當總頁數更改時觸發,$event:number 等於總頁數。
pageChanged − 當頁面更改時觸發,$event:{page, itemsPerPage} 等於包含當前頁面索引和每頁專案數的物件。
示例
由於我們將使用分頁,因此我們必須更新在ngx-bootstrap 模態框章節中使用的 app.module.ts 以使用PaginationModule 和 PaginationConfig。
更新 app.module.ts 以使用 PaginationModule 和 PaginationConfig。
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';
@NgModule({
declarations: [
AppComponent,
TestComponent
],
imports: [
BrowserAnimationsModule,
BrowserModule,
AccordionModule,
AlertModule,
ButtonsModule,
FormsModule,
CarouselModule,
CollapseModule,
BsDatepickerModule.forRoot(),
BsDropdownModule,
ModalModule,
PaginationModule
],
providers: [AlertConfig,
BsDatepickerConfig,
BsDropdownConfig,
BsModalService,
PaginationConfig],
bootstrap: [AppComponent]
})
export class AppModule { }
更新 test.component.html 以使用模態框。
test.component.html
<div class="row">
<div class="col-xs-12 col-12">
<div class="content-wrapper">
<p class="content-item" *ngFor="let content of returnedArray">{{content}}</p>
</div>
<pagination [boundaryLinks]="showBoundaryLinks"
[directionLinks]="showDirectionLinks"
[totalItems]="contentArray.length"
[itemsPerPage]="5"
(pageChanged)="pageChanged($event)"></pagination>
</div>
</div>
<div>
<div class="checkbox">
<label><input type="checkbox" [(ngModel)]="showBoundaryLinks">Show Boundary Links</label>
<br/>
<label><input type="checkbox" [(ngModel)]="showDirectionLinks">Show Direction Links</label>
</div>
</div>
更新 test.component.ts 以對應變數和方法。
test.component.ts
import { Component, OnInit } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { PageChangedEvent } from 'ngx-bootstrap/pagination';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
contentArray: string[] = new Array(50).fill('');
returnedArray: string[];
showBoundaryLinks: boolean = true;
showDirectionLinks: boolean = true;
constructor() {}
pageChanged(event: PageChangedEvent): void {
const startItem = (event.page - 1) * event.itemsPerPage;
const endItem = event.page * event.itemsPerPage;
this.returnedArray = this.contentArray.slice(startItem, endItem);
}
ngOnInit(): void {
this.contentArray = this.contentArray.map((v: string, i: number) => {
return 'Line '+ (i + 1);
});
this.returnedArray = this.contentArray.slice(0, 5);
}
}
構建和啟動
執行以下命令以啟動 Angular 伺服器。
ng serve
伺服器啟動並執行後。開啟 https://:4200。點選“開啟模態框”按鈕並驗證以下輸出。