Cannot create md-table with sort
See original GitHub issueBug, feature request, or proposal:
Bug
What is the expected behavior?
I wanted to implement the md-table
with sorting as in the example https://material.angular.io/components/table/overview
What is the current behavior?
Got error:
ERROR TypeError: Cannot read property ‘mdSortChange’ of undefined
<md-table #table [dataSource]="dataSource" mdSort>
...
import {MdSort} from '@angular/material';
@ViewChild(MdSort) sort: MdSort;
ngAfterViewInit() {
console.log({SORT:this.sort});
}
SORT : undefined
What are the steps to reproduce?
Copy example code from https://material.angular.io/components/table/overview
What is the use-case or motivation for changing an existing behavior?
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
“dependencies”: { “@angular/animations”: “^4.2.6”, “@angular/cdk”: “^2.0.0-beta.8”, “@angular/common”: “^4.0.0”, “@angular/compiler”: “^4.0.0”, “@angular/core”: “^4.0.0”, “@angular/forms”: “^4.0.0”, “@angular/http”: “^4.0.0”, “@angular/material”: “^2.0.0-beta.8”, “@angular/platform-browser”: “^4.0.0”, “@angular/platform-browser-dynamic”: “^4.0.0”, “@angular/router”: “^4.0.0”, “core-js”: “^2.4.1”, “rxjs”: “^5.1.0”, “zone.js”: “^0.8.4” }, “devDependencies”: { “@angular/cli”: “1.2.1”, “@angular/compiler-cli”: “^4.0.0”, “@angular/language-service”: “^4.0.0”, “@tуpes/jasmine”: “~2.5.53”, “@tуpes/jasminewd2”: “~2.0.2”, “@tуpes/node”: “~6.0.60”, “codelyzer”: “~3.0.1”, “jasmine-core”: “~2.6.2”, “jasmine-spec-reporter”: “~4.1.0”, “karma”: “~1.7.0”, “karma-chrome-launcher”: “~2.1.1”, “karma-cli”: “~1.0.1”, “karma-coverage-istanbul-reporter”: “^1.2.1”, “karma-jasmine”: “~1.1.0”, “karma-jasmine-html-reporter”: “^0.2.2”, “protractor”: “~5.1.2”, “ts-node”: “~3.0.4”, “tslint”: “~5.3.2”, “typescript”: “~2.3.3” }
Windows 7 x64, Google Chrome 59.0.3071.115
Is there anything else we should know?
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (1 by maintainers)
Top GitHub Comments
You might forget to import the module : MdSortModule. @see material2/src/demo-app/demo-app-module.ts
fixed it… bug had nothing to do with the CDK table… the md-table was in a *ngIf (which was set to true, but nonetheless caused an undefined mdSort) I (temporarily) fixed it with an [style.visibility] binding.
*anyboddy suggestions how to solve undefined instances due to an ngIf?