【发布时间】:2018-04-25 21:29:30
【问题描述】:
我正在尝试为库构建自定义 ngx 分页,我正在
参考链接https://github.com/michaelbromley/ngx-pagination但我没有
了解我需要做什么来构建自定义分页。它不响应
点击事件。
HTML
<table class="table">
<thead>
<tr>
<th>SL</th>
<th>Ref</th>
<th>Project Name</th>
<th>Product Owner</th>
<th>Project Type</th>
<th>Remaining Days</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let project of projects | paginate: { itemsPerPage: 7, currentPage: p } ;let ndx = index" >
<td>{{ndx+1}}</td>
<td>{{project.ref}}</td>
<td>{{project.projectName}}</td>
<td>{{project.productOwner}}</td>
<td>{{project.projectType}}</td>
<td>{{project.days}}</td>
<td>{{project.status}}</td>
</tr>
</tbody>
</table>
<pagination-template #p="paginationApi"
(pageChange)="pageChange.emit($event)">
<div class="pagination-previous" [class.disabled]="p.isFirstPage()">
<a *ngIf="!p.isFirstPage()" (click)="p.previous()"> < </a>
</div>
<div *ngFor="let page of p.pages" [class.current]="p.getCurrent() === page.value">
<a (click)="p.setCurrent(page.value)" *ngIf="p.getCurrent() !== page.value">
<span>{{ page.label }}</span>
</a>
<div *ngIf="p.getCurrent() === page.value">
<span>{{ page.label }}</span>
</div>
</div>
<div class="pagination-next" [class.disabled]="p.isLastPage()">
<a *ngIf="!p.isLastPage()" (click)="p.next()"> > </a>
</div>
CUSTOM-COMPONENT.TS
@Input() id: string;
@Input() maxSize: number;
@Output() pageChange: EventEmitter<number> = new EventEmitter<number>();
page: number = 1;
pageChanged(event){
console.log("pageChanged");
}
还需要进行哪些更改才能使其正常工作?我在这里遗漏了什么吗?我已经使用 npm 安装了库。请提出建议。
【问题讨论】:
-
我应该在哪里定义行@Output() pageChange: EventEmitter
= new EventEmitter ();
标签: angular