Angular matSort does not sort

后端 未结 8 1758
深忆病人
深忆病人 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:29

    So it's happening because of your this.sort.sortChange method is getting called before your child view Initialize

    You Just need to implement your class from AfterViewInit instead of OnInit

    And use ngAfterViewInit life cycle method

    export class ApplicantListComponent implements AfterViewInit {
        @ViewChild(MatPaginator, { static: false }) paginator: MatPaginator;
        @ViewChild(MatSort, { static: false }) sort: MatSort;
    
        constructor() {}
    
        ngAfterViewInit() {
            this.sort.sortChange.subscribe(() => {
                this.paginator.pageIndex = 0;
                this.paginator.pageSize = this.pageSize;
            });
    } 
    

提交回复
热议问题