垫子分页器问题

时间:2020-01-17 05:44:26

标签: angular7

我在我的项目中使用下面的结构表格。

**<mat-paginator></mat-paginator>
<mat-table></mat-table>
<mat-paginator></mat-paginator>**

In my ts file look like

 **@ViewChild(MatPaginator) paginator: MatPaginator;**


 **Actual problem is first one paginator is working fine and trigger events correctly.
 bottom mat paginator is not working and event is not triggered ,also page,pageIndex is not 
refelecting from first paginator**

1 个答案:

答案 0 :(得分:0)

@ViewChild仅查询一个组件引用。但是您认为有两个组成部分。因此,您必须分别查询两个组件,如下所示。

<mat-paginator #topPageinator></mat-paginator> <mat-table></mat-table> <mat-paginator #bottomPageinator></mat-paginator>

@ViewChild('topPageinator') paginator: MatPaginator; @ViewChild('bottomPageinator') paginator: MatPaginator;

OR

您可以使用@ViewChildren代替@ViewChild

@ViewChildren(MatPaginator) paginators: QueryList<MatPaginator>;