0

I have an application that's been using MatSort in the table for the last 2 years. Over the last week I updated to version 15 and now I discover that my MatSort is always undefined in the AfterViewInit event. I have confirmed that the MatSortModule is imported, so I'm not sure why it's breaking now. Any help is appreciated. Below are my code snippets showing the variable declaration and the afterviewinit event. I have also tried using static: true and static: false.

@ViewChild(MatSort, { static: false }) sort: MatSort;
@ViewChild(MatPaginator, { static: false }) paginator: MatPaginator;
ngAfterViewInit() {
    this.ds;
    this._sorter = this.sort;  // <==  This is always undefined.
    this._paginator = this.paginator;  // <==  Paginator has a value.
}
jhorton
  • 1,019
  • 3
  • 17
  • 36

1 Answers1

1

So it turned out to be an ngIf hiding the table on initial load to show a no data found message. Once I took that out it's populating the MatSort. Hope this helps someone else.

jhorton
  • 1,019
  • 3
  • 17
  • 36