简体   繁体   中英

How to add pagination in angular project using ngx-pagination and show it's status

How to do a pagination status in an angular project like this (dynamically)

I use ngx-pagination

project

在此处输入图像描述

在此处输入图像描述

Where is your problem, can you give further detail?

Here the solution

Stackblitz - my project

component.html

<div class="text-center">
  <h1>ngx-pagination live demo</h1>
</div>

<div class="list">

  <ul
    *ngFor="
      let item of collection | paginate: { itemsPerPage: 10, currentPage: p };
      let ndx = index
    "
  >
    <li>
      {{ item }}
    </li>
  </ul>
  <div class="text-center">Showing {{start==null?1:start }} - {{last==null?10:last}} of 100 results</div>

  <pagination-controls
    (pageChange)="listCount($event)"
    (pageChange)="p = $event"
  ></pagination-controls>
</div>

app.component.css

:host {
  font-family: "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif;
}

.text-center {
  text-align: center;
}

.list {
  max-width: 550px;
  margin: auto;
}

li {
  margin-bottom: 5px;
}

app.component.ts

import { Component } from '@angular/core';
import { Console } from '@angular/core/src/console';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  collection = [];
  start;
  last;
  constructor() {
    for (let i = 1; i <= 100; i++) {
      this.collection.push(`item ${i}`);
    }
  }
  
  listCount(count) {
    this.start = count
    this.start = this.start * 10 - 9
    this.last = count * 10
    if (this.last > this.collection.length) {
      this.last = this.collection.length;
    }
    console.log('start'+ '      '+this.start + '      '+'last' + '      '+ this.last);
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM