【发布时间】:2021-04-22 23:53:50
【问题描述】:
我正在使用 Angular 11 并尝试实现分页
HTML
<tbody>
<tr *ngFor="let order of orders | paginate: config;let i = index">
<th scope="row" style="display:none;">{{ i + 1 }}</th>
<td>{{ order.Code }}</td>
<td>{{ order.quantity }}</td>
</tr>
</tbody>
</table>
<pagination-controls id="basicPaginate" (pageChange)="pageChanged($event)"></pagination-controls>
app.module.ts
.....
import { NgxPaginationModule } from 'ngx-pagination';
imports: [
.......
RouterModule.forRoot(AppRoutes,{
useHash: true
}),
.......
NgxPaginationModule
]
订单组件
export class OrderComponent implements OnInit {
orders : Order [] = [];
config:any;
constructor(private orderService : OrderService {
this.config = {
id: 'basicPaginate',
itemsPerPage: 5,
currentPage: 1,
totalItems: 50
};
}
ngOnInit(){
//web service ok
this.orderService.getAllOrders(30,5,0).pipe(first()).subscribe(orders => this.orders = orders);
}
pageChanged(event) {
this.config.currentPage = event;
}
}
项目编译成功
那么为什么会出现这个错误呢? 我只想要基本的分页而不是自定义的分页。 Angular 11 是否存在兼容性问题?
【问题讨论】:
-
如果您在延迟加载的模块中使用它,您需要在该模块中导入
NgxPaginationModule而不是应用程序模块
标签: html angular typescript angular11 ngx-pagination