Angular MatPaginator not working

前端 未结 30 1550
情歌与酒
情歌与酒 2020-12-04 23:05

I have 2 components. Both have mat-table and paginators and pagination is working for one component and not working for the other component though the code is similar. Below

30条回答
  •  [愿得一人]
    2020-12-04 23:53

    In my case, data coming from service asynchronously so neither could use ngOnInit or ngAfterViewInit, I used ngOnChanges, something like below:

    ngOnChanges(change: SimpleChanges) {
        if (change.properties) {
          if (this.properties.length > 0) {
            this.dataSource = new MatTableDataSource(this.properties);
            this.dataSource.paginator = this.paginator;
          }
        }
      }

    Be sure to set the [DataSource] attribute at mat-table element at html to the data source property from the component so to ensure the data source get bind with the table and paginator.

提交回复
热议问题