简体   繁体   English

Visual Studio Code typescript 自动导入不工作

[英]Visual Studio Code typescript auto import not working

As the title stated my VS Code doesn't auto import my modules, I'm trying to import MatDialogModule in the image below and it doesn't show me any Angular Material options正如标题所述,我的 VS 代码不会自动导入我的模块,我正在尝试在下图中导入MatDialogModule ,但它没有显示任何 Angular 材料选项

在此处输入图像描述

For Angular 13, below solution worked for me: Add this in tsconfig.json under compilerOptions.对于 Angular 13,以下解决方案对我有用:将其添加到 tsconfig.json 下的 compilerOptions 下。

"typeRoots": ["node_modules/@angular/material"]

VSCode is not able to auto import module from directories which have more than two path segments. VSCode 无法从具有两个以上路径段的目录中自动导入模块。 However, this is true only for the first time you import a module inside a project.但是,这仅适用于您第一次在项目中导入模块时。

It's worth checking if you have done this first, import { MatDialogModule } from '@angular/material/dialog';值得检查一下你是否已经这样做了, import { MatDialogModule } from '@angular/material/dialog'; , as the type comes from /dialog directory. ,因为类型来自/dialog目录。

It'd also be more helpful if you could attach your package.json file to your question, and show what you have installed so far.如果您可以将 package.json 文件附加到您的问题,并显示您到目前为止安装的内容,它也会更有帮助。 Did you use Angular CLI to install the Material modules?您是否使用 Angular CLI 来安装 Material 模块?

You might find following links helpful:您可能会发现以下链接有帮助:

As woodykiddy said, is @angular/material a dependency in your package.json?正如 woodykiddy 所说, @angular/material是您的 package.json 中的依赖项吗? If not, add it and run npm i or yarn or the install command for your chosen package manager.如果没有,请添加它并运行npm iyarn或为您选择的 package 管理器运行安装命令。

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

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