Note that paging/sort not work correctly. Paging does not show the number of elements it is showing and sorting does not work, but if you delete the line in the html file
This can be solved by the following strategy:
dataSource = new MatTableDataSource(); @ViewChild(MatSort, {static: false}) set content(sort: MatSort) { this.dataSource.sort = sort; }
Now even if you use *ngIf, it will work.