components: [Table] Throw error if MatSortModule is not imported while using "MatSort/matSort"

Bug, 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.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (2 by maintainers)

Most upvoted comments

In came here because I hit the error @tzachs reported above:

ERROR Error: Uncaught (in promise): HierarchyRequestError: Failed to execute 'appendChild' on 'Node': This node type does not support this method.

In my case the issues was that, by accident, I was placing the mat-sort-header inside the ng-container that preceded the th 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.

Once I added the’import {MatSortModule} from '@angular/material';

I get the following error

ERROR Error: Uncaught (in promise): HierarchyRequestError: Failed to execute 'appendChild' on 'Node': This node type does not support this method.
Error: Failed to execute 'appendChild' on 'Node': This node type does not support this method.
    at DefaultDomRenderer2.webpackJsonp../node_modules/@angular/platform-browser/esm5/platform-browser.js.DefaultDomRenderer2.appendChild (platform-browser.js:2760)
    at AnimationRenderer.webpackJsonp../node_modules/@angular/platform-browser/esm5/animations.js.BaseAnimationRenderer.appendChild (animations.js:457)
    at DebugRenderer2.webpackJsonp../node_modules/@angular/core/esm5/core.js.DebugRenderer2.appendChild (core.js:15264)
    at createElement (core.js:10587)
    at createViewNodes (core.js:13745)
    at callViewAction (core.js:14218)
    at execComponentViewsAction (core.js:14127)
    at createViewNodes (core.js:13812)
    at callViewAction (core.js:14218)
    at execComponentViewsAction (core.js:14127)
    at DefaultDomRenderer2.webpackJsonp../node_modules/@angular/platform-browser/esm5/platform-browser.js.DefaultDomRenderer2.appendChild (platform-browser.js:2760)
    at AnimationRenderer.webpackJsonp../node_modules/@angular/platform-browser/esm5/animations.js.BaseAnimationRenderer.appendChild (animations.js:457)
    at DebugRenderer2.webpackJsonp../node_modules/@angular/core/esm5/core.js.DebugRenderer2.appendChild (core.js:15264)
    at createElement (core.js:10587)
    at createViewNodes (core.js:13745)
    at callViewAction (core.js:14218)
    at execComponentViewsAction (core.js:14127)
    at createViewNodes (core.js:13812)
    at callViewAction (core.js:14218)
    at execComponentViewsAction (core.js:14127)
    at resolvePromise (zone.js:814)
    at resolvePromise (zone.js:771)
    at zone.js:873
    at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:4751)
    at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
    at Zone.webpackJsonp../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
    at drainMicroTaskQueue (zone.js:595)

Any one got this also?