2016-11-10 90 views
1

我有一个角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我导入图标组成部分,声明它和导出。 在共享模块中,我导入了utilities模块并导出它。 在应用程序模块中,我导入共享模块。在我的应用程序组件中,我想要 使用我的图标组件,但出现错误:'app-icon' is not a known element:

是否可以重新导出这样的模块/组件? 如果没有,是否将公用程序模块直接导入应用程序模块的唯一选择?我发现抱怨应用程序图标组件不可用的模块/组件/模板是消息组件。我试图将图标组件直接导入到消息组件中,但它仍然抱怨图标组件不可用。

回答

0

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.

组件/指令/管道没有从父母继承的模块,即MessageModule没有得到任何通过AppModule提供。通过导入包含这些项目的模块,MessageModule需要提供对它需要的任何外部项目的访问。所以你可能只需imports: [ UtilitiesModule ]进入MessageModule,那应该不会引起错误。

如果在UtilitiesModule的内部有MessageModule,则可能会导致电路依赖性错误。我不确定。在这种情况下,您可能需要重组。

+0

感谢您的解释。将图标组件导入消息模块实际上导致了有关在两个模块中声明的图标组件的错误。可能是因为消息模块被公用程序模块导入。无论如何,我只是做了一个图标模块,然后我可以导入到实用程序和消息模块。我不确定这个解决方案有多好,需要深入研究构建角度2。 – Jan