重新导出嵌套模块

Re-export nested modules

我有一个 Angular 2 项目,其结构如下:

/app
    app.component.ts
    app.module.ts
    /shared
           shared.module.ts
           /layout
           /utilities
                     utilities.module.ts
                     /icon
                          icon.component.ts
                     /message
                             message.module.ts
                             message.component.ts <----Problem here

在 utilities.module.ts 中,我导入图标组件,声明并导出它。 在共享模块中,我导入并导出了实用程序模块。 在应用程序模块中,我导入了共享模块。在我的应用程序组件中,我想 使用我的图标组件,但出现错误:'app-icon' is not a known element:

是否可以像这样重新导出 modules/components? 如果没有,是否将实用程序模块直接导入应用程序模块是唯一的选择吗?

编辑: 我注意到抱怨应用程序图标组件不可用的 module/component/template 是消息组件。试过将图标组件直接导入消息组件,还是提示图标组件不可用

Edit: I have noticed that the module/component/template that is complaining that the app-icon component is not available is the message component. I have tried to import the icon component directly into the message component, but it still complains about the icon component not being available.

Component/directives/pipes 不会从父模块继承,即 MessageModule 不会通过 AppModule 获得任何可用。 MessageModule 需要通过导入包含这些项目的模块来提供对其所需的任何外部项目的访问。所以你可能只是 imports: [ UtilitiesModule ] 进入 MessageModule,这样应该不会引发错误。

如果 UtilitiesModule 中有 MessageModule,这可能会导致循环依赖错误。我不知道。在这种情况下,您可能需要重组。