如何使用ngx-pagination对divs进行分页

时间:2018-10-11 12:19:14

标签: angular ngx-pagination

我是新手,所以遇到了这个问题。

<div class="col-md-4" *ngFor="let student of students | paginate: {itemsPerPage:5, currentPage: p, totalItems: len}">
     {{student.name}}
</div>
<pagination-controls (pageChange)="p =$event"></pagination-controls>

我收到此错误

  

无法读取未定义的属性“ totalItems”       在PaginatePipe.push ../ node_modules / ngx-pagination / dist / ngx-pagination.js.PaginatePipe.transform

组件代码:

public students= [];
public len;
ngOnInit() {
    this.serverService.getStudents().subscribe(
      data => {
        this.students= data,
        this.len = this.students.length
      }
    );
  }

3 个答案:

答案 0 :(得分:0)

<tbody *ngFor= "let item of con?.data?.countries | paginate:{itemsPerPage:10,currentPage: p}">
    <tr>
        <td>{{item['name']}}</td>
        <td>{{item['code']}}</td>                             
    </tr>
</tbody>

答案 1 :(得分:0)

我认为您不需要在这里使用 totalItems 作为分页属性。 ngx-pagination 会自动将列表/数组的长度视为项目总数。

<div class="col-md-4" *ngFor="let student of students | paginate: {itemsPerPage:5, currentPage: p}">
     {{student.name}}
</div>
<pagination-controls (pageChange)="p =$event"></pagination-controls>

这将解决您原来的问题/错误:

<块引用>

无法读取未定义的属性“totalItems” PaginatePipe.push../node_modules/ngx-pagination/dist/ngx-pagination.js.PaginatePipe.transform

答案 2 :(得分:-1)

Dim contador As Integer
'Adding DataRow
For Each row As DataGridViewRow In dataCasados.Rows
    If contador Mod 2 = 0 Then
        pdfTable.DefaultCell.BackgroundColor = Color.RED
    Else
        pdfTable.DefaultCell.BackgroundColor = Color.BLUE
    End If

    For Each cell As DataGridViewCell In row.Cells
        pdfTable.AddCell(cell.Value.ToString())
    Next

    contador += 1

Next

example.component.ts:

con:any;

I am working at Angular 8. This code is helpful to use the 
pagination. I declare base url in API_URL in environment.ts.
example: API_URL:"http....",
endpoint: country

HTML code:
<tbody *ngFor= "let item of con?.data?.countries 
|paginate:itemsPerPage:10,currentPage: p}">
<tr>
<td>{{item['name']}}</td>
<td>{{item['code']}}</td>                             
</tr>
</tbody>