Angular matSort does not sort

后端 未结 8 1770
深忆病人
深忆病人 2020-12-09 03:07

I\'m having trouble with importing matSort into my matTable.

I\'m providing you with my code:

dashboard.component.ts



        
8条回答
  •  情书的邮戳
    2020-12-09 03:25

    I had the same issue,

    There are a couple of reasons for this issue

    1. Make sure you have included MatSortModule module in your App module
     import { MatSortModule, MatPaginatorModule, MatTableModule } from '@angular/material';
    
     @NgModule({
      imports: [MatSortModule, MatPaginatorModule, MatTableModule],
      exports: []
    })
    
    1. Make sure you have subscribed sort change in the ngAfterViewInit
      ngAfterViewInit() {
        this.sort.sortChange.subscribe(() => this.paginator.pageIndex = 0 );
      }
    

提交回复
热议问题