【发布时间】:2018-03-17 01:32:41
【问题描述】:
我正在尝试在 Angular 4 中实现分页,但它仍然不起作用。我使用了一项服务来订阅我的数据并将其输出到 html 中,我想通过在其中添加分页来限制它。下面是我的代码。
ts
export class ProductListComponent implements OnInit {
closeResult: string;
products: any;
subscription: Subscription;
constructor(private modalService: NgbModal, private productService: ProductsService) { }
page :number = 1;
ngOnInit() {
this.subscription = this.productService.getAll()
.subscribe(
(data:any) => {
this.products = data;
},
error => {
});
}
}
html
<tbody>
<tr *ngFor="let product of products">
<td>{{ product.name }}</td>
<td>{{ product.desc }}</td>
<td>{{ product.qty }}</td>
<td>{{ product.price }}</td>
<td>
<button type="button" class="btn btn-sm btn-primary"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Edit</button>
</td>
</tr>
</tbody>
</table>
<nav class="pull-right">
<ul class="pagination pagination-sm">
<ngb-pagination [collectionSize]="50" [(page)]="currentPage" size="sm"></ngb-pagination>
</ul>
</nav>
【问题讨论】:
标签: angular pagination ng-bootstrap angular-bootstrap