【发布时间】:2021-08-10 18:03:12
【问题描述】:
我正在使用带有 Angular 语言服务扩展的 VS Code。 VS Code 经常在我的 Angular HTML 模板中错误地报告错误。我可以成功运行 Angular 应用程序,成功运行我的单元测试并成功构建应用程序,而不会看到 VS Code 报告的错误。我已经看到报告了多种类型的错误,但我最常看到的错误如下。我并不总是看到这些误报,但它确实经常发生。有解决办法吗?
'xyz' is not a known element:
1. If 'xyz' is an Angular component, then verify that it is part of this module.
2. If 'xyz' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
【问题讨论】:
-
它有时会在您更改模块时发生。重新启动 VS Code 对我有用。
-
@JCCHH,您的应用程序使用 ng-serve 工作,但是当您使用
ng build时它会给您错误(错误表明您应该将组件添加到一个模块并将此模块导入main.module.ts) -
@Eliseo 正如我所提到的,我能够运行应用程序,进行构建并运行我的测试用例,它们都可以工作。问题在于 VS Code,而不是我的代码。
标签: angular visual-studio-code