【发布时间】:2021-12-12 22:04:04
【问题描述】:
https://ng-bootstrap.github.io/#/components/pagination/overview 中有关 ngb-pagination 的文档导致添加此页面后页面无法加载
<ngb-pagination
[(page)]="page"
[pageSize]="pageSize"
[collectionSize]="items.length"></ngb-pagination>
这是我的HTML 文件
<div class="body d-flex ">
<table class="table table-hover ">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Age</th>
<th scope="col">Email</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let user of users | slice: (page-1) * pageSize : page * pageSize">
<td>{{user.name}}</td>
<td>{{user.age}}</td>
<td>{{user.email}}</td>
<td>action</td>
</tr>
</tbody>
</table>
<ngb-pagination [(page)]="page" [pageSize]="pageSize" [collectionSize]="users.length"></ngb-pagination>
</div>
这是ts 文件
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
@Component({
selector: 'app-table',
templateUrl: './table.component.html',
styleUrls: ['./table.component.scss'],
})
export class TableComponent implements OnInit {
readonly API_PATH = '/user/all';
users: any[] = [];
page = 1;
pageSize = 5;
constructor(private api: HttpClient) {}
async ngOnInit() {
this.displayAllUsers();
}
private async displayAllUsers() {
var users: any = await this.getUsers();
this.getResult(users);
}
private async getUsers(): Promise<any> {
return await this.api.get(environment.API_URL + this.API_PATH).toPromise();
}
private getResult(result: any) {
if (result.success) {
this.users = this.toArray(result.data);
} else {
console.log(result.data);
}
}
private toArray(result: any): any[] {
var list = [];
for (var items in result) {
list.push(result[items]);
}
return list;
}
}
如果我删除ngb-paginationsn-p 页面似乎可以正常加载,但添加 sn-p 将无法加载页面
【问题讨论】:
-
在将我的代码升级到 ng-bootstrap 10 之后,我遇到了同样的问题。在升级之前它一直在工作。
-
见下文。我在使用 Stackblitz 制作代码的简化版本时发现了这个问题。它向我显示了我在 Angular 构建中没有看到的错误消息。某处某处抑制了该消息。
标签: html node.js angular typescript ng-bootstrap