gpt4 book ai didi

angular - 我在我的 angular 应用程序中使用了 ngb 分页,但它无法正常工作

转载 作者:行者123 更新时间:2023-12-03 23:47:14 29 4
gpt4 key购买 nike

我已经在表格中的 angular 应用程序上应用了 NGB 分页,但它不起作用。它只是显示 2 页,而不是在表的页面之间划分数据。我的代码如下:

import { UserService } from './../services/user.service';
import { Component, OnInit } from '@angular/core';
import { UserInfo } from 'src/app/models/user-info';

@Component({
selector: 'app-user',
templateUrl: './user.component.html',
styleUrls: ['./user.component.scss']
})
export class UserComponent implements OnInit {

constructor(private _userService:UserService) { }

ngOnInit() {
this.getUserData();

}


userData=[
{"name":"Akash","email":"akash@gmmail.com"},
{"name":"sumit","email":"sumit@gmmail.com"},
{"name":"mohit","email":"mohit@gmmail.com"},
{"name":"rajesh","email":"rajesh@gmmail.com"},
{"name":"ramesh","email":"ramesh@gmmail.com"},
{"name":"vikas","email":"vikas@gmmail.com"},
{"name":"suresh","email":"suresh@gmmail.com"},
{"name":"ramesh","email":"ramesh@gmmail.com"},
];

elementPerpage:number=5;
currentPage:number=1;
arrayLength:number=this.userData.length;
userInfo:UserInfo[];

这是我的 Html 文件
<h3>User Details</h3>
<div class="table-responsive">
<table class="table table-striped ">
<thead>
<tr>
<th scope="col">User Name</th>
<th scope="col">User Email</th>
</tr>
</thead>
<tbody>
<tr *ngIf="!userData || userData.length === 0">
<td colspan="2" class="text-center">No records</td>
</tr>
<tr *ngFor="let info of userData">
<td>
{{info.name}}
</td>
<td>
{{info.email}}
</td>
</tr>
</tbody>
</table>
</div>
<div >
<ngb-pagination [collectionSize]="arrayLength" [(page)]="currentPage" [pageSize]="elementPerpage">
</ngb-pagination>
</div>

我已将 Bootstrap 添加到项目中,没有错误。但是分页不起作用。我怎样才能使 ngb 分页工作?

最佳答案

请看the pagination docs .
基本用法示例:

<table>
<tr *ngFor="let item of items | slice: (page-1) * pageSize : (page-1) * pageSize + pageSize">
<!-- content here -->
</tr>
</table>

<ngb-pagination
[(page)]="page"
[pageSize]="pageSize"
[collectionSize]="items.length"></ngb-pagination>
* ngFor 包含一个答案(:

关于angular - 我在我的 angular 应用程序中使用了 ngb 分页,但它无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61951630/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com