[Table] Throw error if MatSortModule is not imported while using "MatSort/matSort"
See original GitHub issueBug, feature request, or proposal
Proposal
What is the expected behavior?
Using @ViewChild(MatSort) sort: MatSort;
and <mat-table [dataSource]="dataSource" matSort>
without import { MatSortModule } from '@angular/material';
will throw an error like some other material component (if i remember it’s something like “you need to import xxxx…”)
What is the current behavior?
Nothing, the sorting arrows are just not displayed (and sorting doesn’t work)
What are the steps to reproduce?
Just remove the MatSortModule : https://stackblitz.com/angular/voqnaoexppp?file=main.ts
What is the use-case or motivation for changing an existing behavior?
I lost many hours on this… i take some code from my stackblitz to my main project and continue developping, but after a moment i see sorting doesn’t work anymore without errors in the console… I search, scratch my head, and finally reverse my code to the beginning but still not working !
Finally i found solution online, import MatSortModule… so depressing 😦
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Latest
Is there anything else we should know?
I know it’s my fault, but without error it’s difficult to find this.
Issue Analytics
- State:
- Created 5 years ago
- Comments:19 (2 by maintainers)
Top GitHub Comments
In came here because I hit the error @tzachs reported above:
In my case the issues was that, by accident, I was placing the
mat-sort-header
inside theng-container
that preceded theth
where was suppose to go.@razvanm, you save me much time. after reading your comment, I checked my code and found that I did exactly the same and accidentally placed the mat-sort-header in the ng-container.