首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

在ngx-pagination - angular 9上添加第一页和最后一页

,可以通过自定义模板来实现。

首先,确保已经安装了ngx-pagination模块。可以通过以下命令进行安装:

代码语言:txt
复制
npm install ngx-pagination --save

接下来,在你的组件中引入ngx-pagination模块:

代码语言:txt
复制
import { Component } from '@angular/core';
import { PaginationInstance } from 'ngx-pagination';

@Component({
  selector: 'app-your-component',
  templateUrl: './your-component.component.html',
  styleUrls: ['./your-component.component.css']
})
export class YourComponent {
  public config: PaginationInstance = {
    id: 'custom',
    itemsPerPage: 10,
    currentPage: 1,
    totalItems: 100
  };
}

在模板文件your-component.component.html中,使用ngx-pagination指令来显示分页控件:

代码语言:txt
复制
<pagination-controls (pageChange)="config.currentPage = $event"></pagination-controls>

然后,自定义模板来添加第一页和最后一页按钮。在your-component.component.html中添加以下代码:

代码语言:txt
复制
<pagination-controls (pageChange)="config.currentPage = $event">
  <ng-template #customTemplate let-config="config">
    <ul class="pagination">
      <li class="page-item" [class.disabled]="config.currentPage === 1">
        <a class="page-link" (click)="config.currentPage = 1">第一页</a>
      </li>
      <li class="page-item" [class.disabled]="config.currentPage === config.totalPages">
        <a class="page-link" (click)="config.currentPage = config.totalPages">最后一页</a>
      </li>
      <li class="page-item" [class.disabled]="config.currentPage === 1">
        <a class="page-link" (click)="config.currentPage = config.currentPage - 1">上一页</a>
      </li>
      <li class="page-item" [class.disabled]="config.currentPage === config.totalPages">
        <a class="page-link" (click)="config.currentPage = config.currentPage + 1">下一页</a>
      </li>
    </ul>
  </ng-template>
</pagination-controls>

最后,你可以根据需要自定义样式来美化分页控件。

这样,你就成功在ngx-pagination - angular 9上添加了第一页和最后一页按钮。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

jQuery 实现图片下载代码jQuery 实现图片下载代码

jQuery 实现图片下载代码 function downloadImage(src) { var $a = $("").attr("href", src).attr("download", "meitu.png"); $a[0].click(); } 关键调用downloadImage函数代码 onclick=downloadImage(url) 完整 js 代码 $(function () { $.extend($.fn.bootstrapTable.defaul

03

[angularjs] 前端路由实现单页跳转

代码:

</body> <script src="http://apps.bdimg.com/libs/angular.

01
领券