繁体   English   中英

自定义角度库导入多个模块而不是桶

[英]Custom Angular Library Import multiple Modules not barrel

嗨,我正在尝试构建自定义的Angular库。 使用yeoman-generator( link ),我得到了一个可以构建的模板,效果很好。 问题在于它使用了(不再是最佳实践)barrel index.ts ,而我想要的是每个组件能够有一个模块并相应地导入。

如果有人遇到相同的问题,这是我的文件现在的结构和连接方式:

我有一个具有所需功能HelloWorld的组件

然后是该组件的模块:

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 {}

最后,在index.ts文件中只有这一行:

export * from './hello-world.module';

要在项目中使用app.module.ts导入,请执行以下操作:

import { HelloWorldModule } from 'test-lib'

并将HelloWorldModule添加到imports数组。

暂无
暂无

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

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