【问题标题】:Angular 10 Compile Error "error NG8001: 'mat-card-title' is not a known element:Angular 10 编译错误“错误 NG8001:'mat-card-title' 不是已知元素:
【发布时间】:2021-10-23 17:36:30
【问题描述】:

所以我遇到了一个编译错误,当我输入 ng serve 以在本地查看我的更改时,我的所有组件上的所有导入模块都收到以下错误。

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.

22                     <mat-card-title>Register</mat-card-title>
                       ~~~~~~~~~~~~~~~~

  src/app/landing-page/landing-page.component.ts:8:16
    8   templateUrl: './landing-page.component.html',
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component LandingPageComponent.

我知道这发生在我从 git 存储库的另一个分支中提取之后,并且在我的项目中添加了一个名为“node_modules”的新文件夹,在此之前一切都很好。这以前没有发生过,那么我可以做些什么来缓解这个问题?

是否需要将模块再次导入到各个组件的 .ts 文件中?

控制台错误截图:

谢谢!

【问题讨论】:

  • 请不要将node_modules 文件夹检查到源代码管理中。 package.jsonpackage-lock.json 就是您所需要的。如果您删除 package-lock.jsonnode_modules 文件夹并再次运行 npm install 它应该可以解决。 (package-lock 和 node_modules 都将在运行 install 命令后重新创建,只需确保在 .gitignore 文件中包含 node_modules)。

标签: html angular typescript


【解决方案1】:

您需要运行npm install 来安装添加的新软件包。 如果问题仍然存在,您需要安装角度材料ng add @angular/material,然后安装npm install,对于路由器问题,请尝试此链接Angular router-outlet not recognized

【讨论】:

  • 非常感谢!
猜你喜欢
  • 2020-03-14
  • 2021-09-16
  • 2021-01-27
  • 2020-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多