Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material MatTableDataSource cannot be found

I'm trying to create a table using Angular Material Table, in the examples there is always the import:

import {MatTableDataSource} from '@angular/material';

I'm trying to do the same but I'm getting an error: "Module '../node_modules/@angular/material/material' has no exported member MatTableDataSource.

Is there anything I'm missing?

Here's the package.json versions:

"dependencies": {
 "@angular/animations": "^4.4.6",
 "@angular/cdk": "^2.0.0-beta.12",
 "@angular/common": "^4.2.4",
 "@angular/compiler": "^4.2.4",
 "@angular/core": "^4.2.4",
 "@angular/forms": "^4.2.4",
 "@angular/http": "^4.2.4",
 "@angular/material": "^2.0.0-beta.12",
 "@angular/platform-browser": "^4.2.4",
 "@angular/platform-browser-dynamic": "^4.2.4",
 "@angular/router": "^4.2.4",
 "bootstrap": "^3.3.7",
 "core-js": "^2.4.1",
 "pdfmake": "^0.1.33",
 "rxjs": "^5.4.2",
 "zone.js": "^0.8.14"
},
"devDependencies": {
 "@angular/cli": "1.4.9",
 "@angular/compiler-cli": "^4.2.4",
 "@angular/language-service": "^4.2.4",
 "@types/jasmine": "~2.5.53",
 "@types/jasminewd2": "~2.0.2",
 "@types/node": "~6.0.60",
 "codelyzer": "~3.2.0",
 "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.2.0",
 "tslint": "~5.7.0",
 "typescript": "~2.3.3"
}
like image 487
Lukozaver Avatar asked Dec 03 '22 21:12

Lukozaver


2 Answers

I was having the same problem. Turns out, MatTableDataSource is new feature in Angular Material 5.0.0-rc0. I updated angular 4 to angular 5 and updated angular material to 5.0.0-rc0. (ref: https://github.com/angular/material2/releases)

If it helps, here is my package.json file.

{
  "name": "angular-quickstart",
  "version": "1.0.0",
  "description": "QuickStart package.json from the documentation, supplemented with testing support",
  "scripts": {
    "build": "tsc -p src/",
    "build:watch": "tsc -p src/ -w",
    "build:e2e": "tsc -p e2e/",
    "serve": "lite-server -c=bs-config.json",
    "serve:e2e": "lite-server -c=bs-config.e2e.json",
    "prestart": "npm run build",
    "start": "concurrently \"npm run build:watch\" \"npm run serve\"",
    "pree2e": "npm run build:e2e",
    "e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
    "preprotractor": "webdriver-manager update",
    "protractor": "protractor protractor.config.js",
    "pretest": "npm run build",
    "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
    "pretest:once": "npm run build",
    "test:once": "karma start karma.conf.js --single-run",
    "lint": "tslint ./src/**/*.ts -t verbose"
  },
  "keywords": [],
  "author": "",
  "license": "MIT",
  "dependencies": {
    "@angular/animations": "^5.0.2",
    "@angular/cdk": "^5.0.0-rc0",
    "@angular/common": "^5.0.2",
    "@angular/compiler": "^5.0.2",
    "@angular/core": "^5.0.2",
    "@angular/forms": "^5.0.2",
    "@angular/http": "^5.0.2",
    "@angular/material": "^5.0.0-rc0",
    "@angular/platform-browser": "^5.0.2",
    "@angular/platform-browser-dynamic": "^5.0.2",
    "@angular/router": "^5.0.2",
    "angular-in-memory-web-api": "~0.5.1",
    "angular-material": "^1.1.5",
    "core-js": "^2.5.1",
    "hammerjs": "^2.0.8",
    "rxjs": "^5.5.2",
    "systemjs": "0.20.19",
    "zone.js": "^0.8.18"
  },
  "devDependencies": {
    "concurrently": "^3.5.0",
    "lite-server": "^2.3.0",
    "typescript": "~2.6.0",
    "canonical-path": "0.0.2",
    "tslint": "^5.8.0",
    "lodash": "^4.17.4",
    "jasmine-core": "~2.8.0",
    "karma": "^1.7.1",
    "karma-chrome-launcher": "^2.2.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.2.0",
    "rimraf": "^2.6.2",
    "@types/node": "^6.0.46",
    "@types/jasmine": "2.5.36"
  },
  "repository": {}
}
like image 175
YouKnowMe Avatar answered Dec 29 '22 07:12

YouKnowMe


Just Import by adding the folder name after 'material' like below,

import { MatTableDataSource } from '@angular/material/table'

This has solved the issue.hope it will solve your issue

like image 21
sachinbhorkar Avatar answered Dec 29 '22 08:12

sachinbhorkar