简体   繁体   English

WebStorm 无法识别某些 Angular 组件 - mat-toolbar 未知元素

[英]WebStorm not recognising some Angular components - mat-toolbar unknown element

I am using Angular 5 with Angular material and WebStorm version 2017.3.1我将 Angular 5 与Angular 材料和 WebStorm 版本 2017.3.1 一起使用

When I try to use the <mat-toolbar> element with the following code当我尝试使用带有以下代码的<mat-toolbar>元素时

app.module.ts app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import {MatToolbarModule} from '@angular/material';

import { AppComponent } from './app.component';


@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,

    MatToolbarModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.html应用程序组件.html

<mat-toolbar>
  <span>Title</span>
</mat-toolbar>

WebStorm gives me an error: WebStorm 给了我一个错误:

'mat-toolbar' is not a known element:
1. If 'mat-toolbar' is an Angular component, then verify that it is part of this module.

在此处输入图片说明

However , this renders correctly in the browser:但是,这在浏览器中正确呈现:

在此处输入图片说明

Because it is included in the module with this line import {MatToolbarModule} from '@angular/material';因为它包含在此行中的模块中的import {MatToolbarModule} from '@angular/material'; and

imports: [
  BrowserModule,

  MatToolbarModule
],

Is there something I'm missing here?有什么我在这里想念的吗? Why does WebStorm (and also when running tests via ng test ) give me this error?为什么 WebStorm(以及通过ng test运行测试时)给我这个错误? How can I prevent this error/warning?如何防止此错误/警告?

This error is generated via TypeScript.此错误是通过 TypeScript 生成的。

You can see the error in the console if you click on the TypeScript tab at the bottom.如果单击底部的 TypeScript 选项卡,您可以在控制台中看到错误。

在此处输入图片说明

It's possible to make this error go away if you force the TypeScript service to restart by clicking on the arrow in a circle.如果您通过单击圆圈中的箭头强制重新启动 TypeScript 服务,则可以消除此错误。

在此处输入图片说明

This requires a compile first .这需要先编译

So far, I cannot find a way to map this to a shortcut.到目前为止,我找不到将其映射到快捷方式的方法。

Thanks to @lena and @Z.Bagley for helping me figure this out.感谢@lena 和@Z.Bagley 帮助我解决了这个问题。

The error comes from Angular language service .错误来自Angular 语言服务
Looks related to https://github.com/angular/angular/issues/14961 ;看起来与https://github.com/angular/angular/issues/14961相关; see if updating Typescript to 2.5.2+ helps看看更新 Typescript 到 2.5.2+ 是否有帮助

I know this isn't the problem the OP had, but wanted to share this in case someone comes across this post and is still experiencing this problem in WebStorm and are not getting TypeScript compile errors, here's what worked for me: In WebStorm select menu item File > Invalidate Caches / Restart.我知道这不是 OP 的问题,但我想分享一下,以防有人遇到这篇文章并且在 WebStorm 中仍然遇到这个问题并且没有遇到 TypeScript 编译错误,这对我有用:在 WebStorm 中选择菜单项目文件 > 使缓存无效/重新启动。 This problem happened to me in WebStorm 2019.3 .这个问题在 WebStorm 2019.3 中发生在我身上。

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

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