[英]How to enable auto import for custom Angular library in WebStorm / PhpStorm?
I'm trying to create an Angular 9 library with some components and classes I use in different projects.我正在尝试创建一个 Angular 9 库,其中包含我在不同项目中使用的一些组件和类。 What I did:
我做了什么:
ng new my-lib-project --create-application=false
cd my-lib-project
ng generate library my-lib --prefix lb
projects/my-lib/src/lib/
with an easy LibTestClass definition (see below)projects/my-lib/src/lib/
中创建了一个 test-class.ts 文件,其中包含一个简单的 LibTestClass 定义(见下文)export * from './lib/test-class';
export * from './lib/test-class';
to the public-api.ts file.ng build my-lib
and copied the result to myOtherProject/node_modules/
ng build my-lib
并将结果复制到myOtherProject/node_modules/
Problem: when I type const test = new LibTestClass();
问题:当我输入
const test = new LibTestClass();
in the app.component.ts file of the myOtherProject, PhpStorm does not show the import hint to easily add the import line for TestClass.在 myOtherProject 的 app.component.ts 文件中,PhpStorm 不显示导入提示,以便轻松添加 TestClass 的导入行。 How can I make this auto import work for my custom library?
如何使此自动导入适用于我的自定义库?
Further information:更多信息:
test-class.ts:测试类.ts:
export class LibTestClass {
private test = '';
constructor() {}
}
Thanks to @lena I found the answer: In order to enable import hints for your Angular library you have to install a (local) dependency to your library build.感谢@lena,我找到了答案:为了为您的 Angular 库启用导入提示,您必须为您的库构建安装一个(本地)依赖项。 In my case the solution is:
就我而言,解决方案是:
npm install --save ../my-lib-project/dist/my-lib
This creates a link to the local build of your library and is updated automatically when you build your library.这将创建一个指向您的库的本地构建的链接,并在您构建您的库时自动更新。 I recommend to use
ng build --watch
in development.我建议在开发中使用
ng build --watch
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.