首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ngx-pagination - angular 9上添加第一页和最后一页

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

Stack Overflow用户
提问于 2020-04-25 19:24:40
回答 1查看 1.1K关注 0票数 2

我正在为我的angular应用程序使用ngx-pagination库。除了上一页和下一页按钮,我想添加更多的按钮去直接在最后一页或第一页。我如何才能做到这一点?

模板逻辑

代码语言:javascript
复制
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);
  }

}
代码语言:javascript
复制
<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>

EN

回答 1

Stack Overflow用户

发布于 2021-08-31 08:35:01

您可以自定义分页模板并尝试添加这些按钮

代码语言:javascript
复制
    <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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61424849

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档