English 中文(简体)
Angular Material 7 - Paginator
  • 时间:2024-12-22

Angular Material 7 - Paginator


Previous Page Next Page  

The <mat-paginator>, an Angular Directive, is used to show a navigator with paged information.

In this chapter, we will showcase the configuration required to show a paginator using Angular Material.

Following is the content of the modified module descriptor app.module.ts.

import { BrowserModule } from  @angular/platform-browser ;
import { NgModule } from  @angular/core ;
import { AppComponent } from  ./app.component ;
import {BrowserAnimationsModule} from  @angular/platform-browser/animations ;
import {MatPaginatorModule} from  @angular/material 
import {FormsModule, ReactiveFormsModule} from  @angular/forms ;
@NgModule({
   declarations: [
      AppComponent
   ],
   imports: [
      BrowserModule,
      BrowserAnimationsModule,
      MatPaginatorModule,
      FormsModule,
      ReactiveFormsModule
   ],
   providers: [],
   bootstrap: [AppComponent]
})
export class AppModule { }

Following is the content of the modified HTML host file app.component.html.

<mat-paginator [length] = "100"
   [pageSize] = "10"
   [pageSizeOptions] = "[5, 10, 25, 100]"
   (page) = "pageEvent = $event">
</mat-paginator>
<span *ngIf = "pageEvent">
   <h5>Page Change Event</h5>
   <span>List length: {{pageEvent.length}}</span>
   <span>Page size: {{pageEvent.pageSize}}</span>
   <span>Page index: {{pageEvent.pageIndex}}</span>
</span>

Result

Verify the result.

Paginator

Details

    Here, we ve created a paginator using mat-paginator and handles its change event.

Advertisements