问题
Which Angular Material version should I install to be compatible with Angular4?
I have used below command to install angular Material on the top of Angular 4 project.
npm install @angular/materail
npm install @angular/cdk
npm install @angular/animations
While I try to run the app I am getting below error.
/node_modules/@angular/cdk/observers/typings/observe-content.d.ts (33,22): Type 'ElementRef' is not generic.
回答1:
I would advise you to update your project to the latest version of angular. For stability, features and performance reasons. Also finding documentation/guides about such old version is a lot more difficult.
Besides that, if you want to install material for such an old angular version, you should use the 2.0.0-beta.12
version, which is compatible with angular 4:
npm install @angular/material@2.0.0-beta.12
回答2:
Let me write the steps with more details to make it easier for beginners. Though the question is specific to version 4, the answer is applicable to all versions.
I had faced some issues with latest angular material version 9 as my angular version was 8. So I had to found the compatible version of angular material. Below are the steps I followed:
1- Check the package.json file and notice the major version of angular modules. As shown below- core, compiler, common etc are having version as 8.2.14. Major version is 8.
2- Go to https://material.angular.io/ and on right hand top corner find the material version with same major version (8.2.3 in my case). Refer pic below.
3- Thus for angular v8.2.24, I found compartible angular material verison as 8.2.3. And it working with out any error.
回答3:
They have renamed as Angular/Components. May be you can try V2.0.0-beta.12 and check whether it helps.
npm install @angular/materail@2.0.0-beta.12 npm install @angular/cdk@2.0.0-beta.12 npm install @angular/animations
回答4:
You can choose a version between 2.0.0-beta.3
and 2.0.0-beta.12
depending on your minor angular version. Refer to package.json file in @angular/material repository to determine which one is more fittable to you.
来源:https://stackoverflow.com/questions/56341559/which-angular-material-version-should-i-install-to-be-compatible-with-angular4