[英]Custom Angular Library Import multiple Modules not barrel
Hi I am trying to build a custom Angular Library. 嗨,我正在尝试构建自定义的Angular库。 Using yeoman-generator ( link ) I get a template to build upon, that works just fine.
使用yeoman-generator( link ),我得到了一个可以构建的模板,效果很好。 The problem is that it uses a (not anymore best practice) barrel
index.ts
, and what I want is to be able to have one module per component and import accordingly. 问题在于它使用了(不再是最佳实践)barrel
index.ts
,而我想要的是每个组件能够有一个模块并相应地导入。
In case someone faces the same problem, here is how my files are now structured and connected: 如果有人遇到相同的问题,这是我的文件现在的结构和连接方式:
I have a component with the desired functionality HelloWorld
我有一个具有所需功能
HelloWorld
的组件
Then a module for this component: 然后是该组件的模块:
import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HelloWorld } from './hello-world.component';
export * from './hello-world.component';
@NgModule({
imports: [
CommonModule
],
declarations: [
HelloWorld,
],
exports: [
HelloWorld,
]
})
export class HelloWorldModule {}
And finally inside the index.ts
file is only this line: 最后,在
index.ts
文件中只有这一行:
export * from './hello-world.module';
To use in the projects the app.module.ts
import is: 要在项目中使用
app.module.ts
导入,请执行以下操作:
import { HelloWorldModule } from 'test-lib'
and also add HelloWorldModule
to the imports array. 并将
HelloWorldModule
添加到imports数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.