简体   繁体   English

如何将@angular/material 添加到旧的 angular 项目中?

[英]How to add @angular/material to an old angular project?

I installed @angular/material using npm i @angular/material but every time i start angular app using npm start it throws below error:我使用npm i @angular/material安装了@angular /material 但每次我使用npm start启动 angular 应用程序时都会引发以下错误:

node_modules/@angular/material/index.d.ts' is not a module

slice of my package.json:我的 package.json 的切片:

  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.4",
    "@angular/cli": "~8.3.4",
    "@angular/compiler-cli": "~8.2.5",
    "@angular/language-service": "~8.2.5",
    "@types/node": "~8.9.4",

I tried different versions of angular-material but still getting same error.我尝试了不同版本的 angular-material 但仍然遇到相同的错误。

you can do that via the angular-cli:你可以通过 angular-cli 做到这一点:

ng add @angular/material

The ng add command will install Angular Material, the Component Dev Kit (CDK), Angular Animations and ask you the following questions to determine which features to include: ng add 命令将安装 Angular 材料、组件开发工具包 (CDK)、Angular 动画,并询问您以下问题以确定要包含哪些功能:

  • Choose a prebuilt theme name, or "custom" for a custom theme : You can choose from prebuilt material design themes or set up an extensible custom theme.为自定义主题选择预建主题名称或“自定义” :您可以从预建材料设计主题中进行选择或设置可扩展的自定义主题。

  • Set up global Angular Material typography styles : Whether to apply the global typography styles to your application.设置全局 Angular 材质排版 styles :是否将全局排版 styles 应用于您的应用程序。

  • Set up browser animations for Angular Material : Importing the BrowserAnimationsModule into your application enables Angular's animation system.为 Angular 材料设置浏览器动画:将 BrowserAnimationsModule 导入应用程序可启用 Angular 的 animation 系统。 Declining this will disable most of Angular Material's animations.拒绝此项将禁用 Angular 材质的大部分动画。

you can read more here https://material.angular.io/guide/getting-started你可以在这里阅读更多https://material.angular.io/guide/getting-started

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM