2016-11-10 138 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