angular2 material paginator MatPaginator MatPaginatorIntl

前端之家收集整理的这篇文章主要介绍了angular2 material paginator MatPaginator MatPaginatorIntl前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

angular material的网站上看个自定义分页看了半天没看懂,,
后来去stackoverflow上看到了个回答:https://stackoverflow.com/questions/47593692/how-to-translate-mat-paginator-in-angular4
代码
https://stackblitz.com/edit/angular-5mgfxh?file=main.ts
解决了我的问题。
0.导入MatPaginatorModule
1.新建一个my-paginator.ts文件:

import { MatPaginatorIntl } from '@angular/material';
const getRangeLabel = (page: number,pageSize:number,length:number){
    if(length ===0 || pageSize === 0) {
        return '0 of ' + length;
    }
    legnth = Math.max(length,0);
    const startIndex = page * pageSzie;
    const endIndex = startIndex < length ? Math.min(startIndex + pageSize,length): startIndex + pageSize;
    return '第' + (startIndex + 1) + ' - ' + endIndex + '条,共 ' length' + length + '条';
}

export function myPaginator(){
    const p = new MatPaginatorIntl();
    p.itemsPerPageLabel = '当前页数';
    p.nextPageLabel = '下一页';
    p.prevIoUsPageLabel = '上一页';
    p.firstPageLabel = '第一页';
    p.lastPageLabel = '最后一页';
    return p;
}

2.在module的providers里加入:

providers: [
    { provide: MatPaginatorIntl,useValue: myPaginator() }
  ]

3.正常的使用paginator组件

<mat-paginator [length]="100" [pageSize]="10"></mat-paginator>
原文链接:https://www.f2er.com/angularjs/144893.html

猜你在找的Angularjs相关文章