简体   繁体   English

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

[英]Adding first page and last page on ngx-pagination - angular 9

I am using the ngx-pagination library for my angular app.我正在为我的 angular 应用程序使用 ngx-pagination 库。 Besides the previous and next button I want to add 2 more buttons to go directly on the last page or on the first page.除了上一个和下一个按钮,我想直接在最后一页或第一页上向 go 添加 2 个按钮。 How can I achieve this?我怎样才能做到这一点?

Template logic模板逻辑

 import { Component, OnInit } from '@angular/core'; import { TestimonialsDataService } from '../../services/testimonials-data.service'; @Component({ selector: 'app-card', templateUrl: './card.component.html', styleUrls: ['./card.component.scss'] }) export class CardComponent implements OnInit { public authors: Object = {}; public pageList: number = 1; constructor(private _testimonialsService: TestimonialsDataService) { } ngOnInit(): void { this._testimonialsService.getData().subscribe(data => this.authors = data); } }
 <div class="container"> <div class="content"> <div class="card" *ngFor="let author of authors['user'] | paginate: {id: 'list-pagination', itemsPerPage: 9, currentPage: pageList}" > <div class="card-content"> <img class="image" src="{{author.image}}"/> <p class="author">{{author.name}}</p> <p class="job">{{author.job}}</p> <p class="company"><a href="https://www.materahub.com/">{{author.company}}</a></p> <p class="country"><span class="flag flag-IT"></span><span class="country">{{author.country}}</span></p> </div> </div> </div> <pagination-controls id="list-pagination" lastLabel="Next" class="list-pagination" directionLinks="true" (pageChange)="pageList = $event"></pagination-controls> </div>

You can customize the pagination-template and try adding these buttons您可以自定义分页模板并尝试添加这些按钮

    <pagination-template #p="paginationApi" [id]="config.id 
     (pageChange)="config.currentPage = $event">
            <div class="custom-pagination">
                <div class="pagination-first-page">
                  <span (click)="p.setCurrent(1)">
                    First Page 
                  </span> 
                </div>
              <div class="pagination-previous" [class.disabled]="p.isFirstPage()">
                <span *ngIf="!p.isFirstPage()" (click)="p.previous()">
                  < 
                    </span> 
                </div> 
                <div class="page-number" *ngFor="let page of p.pages" [class.current]="p.getCurrent() === page.value">
                      <span (click)="p.setCurrent(page.value)" *ngIf="p.getCurrent() !== page.value">{{ page.label }}</span>
                    <div *ngIf="p.getCurrent() === page.value">
                      <span>{{ page.label }}</span>
                    </div>
                </div>
                <div class="pagination-next" [class.disabled]="p.isLastPage()">
                  <span *ngIf="!p.isLastPage()" (click)="p.next()"> > </span>
                </div>
                <div class="pagination-last-page">
                  <span (click)="p.setCurrent(p.getLastPage())">
                    Last Page 
                  </span> 
                </div>
            </div>
        
          </pagination-template>
        

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Angular 获取 ngx-pagination 中的最后页码 - How to get the last page number in ngx-pagination using Angular 如何为 Angular 中的表格正确实现 ngx-pagination? - How to properly implement ngx-pagination for tables in Angular? 如何在 ngx-pagination 中制作过滤器 - How make filter in ngx-pagination 如何在 Angular 分页中隐藏最后一个页码? - How to hide last page number in Angular pagination? 角度分页,通过控制器设置首页 - Angular pagination, set first page via the controller 如何使用 ngx-pagination 在 ionic4 app 中对数据进行分页? - how to paginate data in ionic4 app with ngx-pagination? 如何在 Laravel 中禁用分页指示第一页、最后一页和指示上一页、下一页 - How to disable pagination indicately first page, last page & indicately previous page, next page in Laravel 在 Tabulator JS 中禁用分页工具提示按钮(第一个、最后一个、页码(1、2、3)) - Disable pagination tooltip buttons (first, last, page numbers(1, 2, 3)) in Tabulator JS 如何导航到第一页和最后一页antd分页(反应) - How to navigate to the first and last page antd Pagination (React) Angular DataTables 在点击返回时返回到分页的第一页 - Angular DataTables back to the first page in pagination when click back
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM