角度分页器问题

问题描述

mat表格中的每页项目选项有问题,我使用的是Angular 9,因此在渲染表格时,我尝试选择一个已经添加到HTML中的选项:

 <mat-paginator  [pageSizeOptions]="[5,10,20]" [pageSize]="10" showFirstLastButtons></mat-paginator>

因此,我在弹出窗口中显示表格,此外,我发现垫选择显示在弹出窗口的后面,我不知道为什么,但是我只能更改每页项目的值使用屏幕底部或下方的键盘箭头,如屏幕截图所示:

pic 1

pic 2

您能帮我在弹出窗口中每页显示项目吗?

解决方法

您使用的是什么版本的材料? 顺便说一句,如果您在物料对话框中有物料表和分页器,则需要进行说明

this.dataSource.paginator = this.paginator;

打开垫对话框。为此,当打开mat-dialog时,您订阅afterOpened()

openDialog(): void {
    const dialogRef = this.dialog.open(DialogOverviewExampleDialog,{
      width: '250px',data: ...
    });

    //After opened,you indicate that the dataSource.paginator is the "paginator"
    dialogRef.afterOpened().subscribe(res=>{
      dialogRef.componentInstance.dataSource.paginator = 
           dialogRef.componentInstance.paginator)
    })

    dialogRef.afterClosed().subscribe(result => {
        ....
    });
  }