'@angular/材料'组件不起作用。在IDE中显示错误
我在项目中遇到了一个奇怪的问题。有一天,我打开了项目,只是为了找到填充有错误的HTML文件。一些示例是:
- “ Mat-Menu”不是已知的元素
- “ Mat-Tab-group”不是已知的元素
- ,更令人困惑,<路由器 - gt> 基本上不是已知的元素
,我所有的“@Angular/材料”组件都显示不存在,并且在项目中尚不清楚。诸如NGFO和NGIF之类的操作还显示出诸如以下错误:
- 属性绑定ngforof在嵌入式模板上未使用任何指令。确保正确拼写属性名称,并在“@ngmodule.declarations”中列出所有指令。 NG
- 不能与“ Ngforof”结合,因为它不是“ Div”的已知属性。我
知道我的NGFOR和NGIF语句正常工作,因为在发生这些错误之前,没有问题。
但是,当我使用“ NG服务”并打开Chrome时,应用程序会运行,所有材料组件都可以按照应有的方式运行。它仅显示为在我的VSCODE IDE中存在错误,并且不会干扰构建应用程序。
我通过“共享/材料”和“共享/共享.module”导入材料组件。我可以肯定地说,我所有的模块和路由文件都可以与适当的导入和导出正常合作,因为我在上次编辑中没有触摸它们,这是没有错误的。
为什么这怎么会发生?
I'm experiencing a weird issue within my project. I opened up my project one day only to find my HTML files filled with errors. Some examples are:
- 'mat-menu' is not a known element
- 'mat-tab-group' is not a known element
- And more confusingly, < router-outlet > is not a known element
Basically, all my '@angular/material' components are shown to be non-existent and aren't known within the project. Operations such as ngFor and ngIf also show errors such as:
- Property binding ngForOf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ng
- Can't bind to 'ngForOf' since it isn't a known property of 'div'. ng
I know my ngFor and ngIf statements are working properly because before these errors occurred, there were no issues.
However, when I use 'ng serve' and open up Chrome, the application runs, and all material components operate as they should. It only shows up as having errors within my VSCode IDE, and doesn't interfere with building the app.
I imported the material components via 'shared/material.module' and 'shared/shared.module'. I can say for certain that all my module and routing files are working properly with the proper imports and exports because I have not touched them during my last edit, which was error-free.
Why and how could this be happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎是您的IDE问题。您必须在
node_modules
文件夹中通过源文件(Angular Core,材料模块)探索。然后,IDE应该向您显示此属性的正确查看。Seems like your IDE issue. You have to explore through the source files (Angular Core, Material modules) in
node_modules
folder. And then IDE should show you properly view for this attributes.这对我有用。
您需要在项目文件夹中运行此CMD,然后关闭VS代码,然后再次使用项目文件夹打开
This worked for me.
You need to run this cmd in the project folder and then close VS code and open again with the project folder