Reputation: 635
I am trying to implement a <mat-table>
as described in the Material Documentation
TL;DR: After upgrading @angular/core, @angular/material, and @angular/CDK to version 5, I suddenly can't use mat-card -related tags.
I can't get all the dependencies correct to be able to import MatTableDataSource. I realize I could implement my own DataSource like this, but if it's in the documentation, surely a working configuration is possible without this hack. Implementing my own DataSource would also mean losing the pretty sortable headers and filtering, which is what I'm mostly after.
I upgraded the project to Angular 5 thinking Material would be upgraded as well, but that was not the case. Material and CDK stayed at "^2.0.0-beta.12".
After npm install
I saw these warnings:
npm WARN @angular/[email protected] requires a peer of @angular/core@~5.1.1 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/[email protected] requires a peer of @angular/common@~5.1.1 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/[email protected] requires a peer of @angular/core@~5.1.1 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/[email protected] requires a peer of @angular/common@~5.1.1 but none is installed. You must install peer dependencies yourself.
npm WARN @ng-bootstrap/[email protected] requires a peer of @angular/core@^4.0.3 but none is installed. You must install peer dependencies yourself.
npm WARN @ng-bootstrap/[email protected] requires a peer of @angular/common@^4.0.3 but none is installed. You must install peer dependencies yourself.
npm WARN @ng-bootstrap/[email protected] requires a peer of @angular/forms@^4.0.3 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/core@^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/core@^2.0.0||^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/http@^2.0.0||^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/compiler@^2.3.1 || >=4.0.0-beta <5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/core@^2.3.1 || >=4.0.0-beta <5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
...but ng build succeeds and the rest of my app runs fine with these in package.json:
dependencies": {
"@angular/animations": "^5.2.0",
"@angular/cdk": "^2.0.0-beta.12",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/material": "^2.0.0-beta.12",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/platform-server": "^5.2.0",
"@angular/router": "^5.2.0",
"@ng-bootstrap/ng-bootstrap": "1.0.0-beta.6",
"angular-material-prefix-updater": "0.0.6",
"angular2-flash-messages": "^1.0.8",
"angular2-jwt": "^0.2.3",
"core-js": "^2.5.3",
"moment": "^2.20.1",
"ng2-file-upload": "^1.3.0",
"ngx-pagination": "^3.0.3",
"quill": "^1.3.4",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "^1.6.3",
"@angular/compiler-cli": "^5.2.0",
"@angular/language-service": "^4.4.6",
"@types/jasmine": "^2.8.3",
"@types/jasminewd2": "^2.0.3",
"@types/node": "^6.0.96",
"codelyzer": "~3.0.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "^1.7.1",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.3.3",
"karma-jasmine": "^1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.0.4",
"tslint": "~5.3.2",
"typescript": "2.4.2",
"webpack": "^3.10.0"
}
At this point, I still cannot import MatTableDataSource:
...node_modules/@angular/material/material"' has no exported member 'MatTableDataSource'.
...so I increased the Material and CDK versions:
git diff package.json
:
"dependencies": {
"@angular/animations": "^5.2.0",
- "@angular/cdk": "^2.0.0-beta.12",
+ "@angular/cdk": "^5.0.0-rc0",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
- "@angular/material": "^2.0.0-beta.12",
+ "@angular/material": "^5.0.0-rc0",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/platform-server": "^5.2.0",
.
.
Now I can ng build without problems, but when my pages render I see this in the console:
Uncaught Error: Template parse errors:
'mat-card-title' is not a known element:
1. If 'mat-card-title' is an Angular component, then verify that it is part of this module.
2. If 'mat-card-title' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
...and now I'm completely confused and stumped. There is one of the above error for every 'unknown' material card -related tag I have used in my templates. What have I done wrong to suddenly not have material cards available for use?
Upvotes: 6
Views: 8424
Reputation: 635
In hopes that this will help someone in the same situation: the solution was not directly related to package dependencies. I was not importing MatCardModule in @NgModule imports.
Such an obvious answer! ...but, I will have to check change logs and documentation to find why that import was not required before, when I was at a lower version of CDK and Material. The template parse errors only showed up after jumping to a (much) higher version.
Upvotes: 14