[英]Visual Studio Code typescript auto import not working
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:您可能会发现以下链接有帮助:
https://material.angular.io/guide/getting-started https://material.angular.io/guide/getting-started
https://material.angular.io/components/dialog/api https://material.angular.io/components/dialog/api
https://www.c-sharpcorner.com/article/angular-material-from-beginning/ https://www.c-sharpcorner.com/article/angular-material-from-beginning/
https://yogeshdo.net.com/angular-material-installation-setup-visual-studio-code/ https://yogeshdo.net.com/angular-material-installation-setup-visual-studio-code/
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 i
或yarn
或为您选择的 package 管理器运行安装命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.