簡體   English   中英

我無法將一個模塊中的組件用於另一個模塊組件

[英]I cannot use component from one module into another module component

我有兩個模塊,MapModule 和 LeftListModule。 在 MapModule 內部,我有 MapComponent,在 LeftListModule 內部,LeftListContainerComponent。

我要的是將LeftListContainerComponent用進MapComponent中,如下

<p>map works!</p>
<app-left-list-container></app-left-list-container>

為此,我以這種方式配置了 LeftListModule

@NgModule({
  declarations: [LeftListContainerComponent],
  imports: [
    CommonModule
  ],
  exports:[LeftListContainerComponent]
})
export class LeftListModule { }

還有像這樣的 MapModule

@NgModule({
  declarations: [MapComponent, LeftListContainerComponent],
  imports: [
    CommonModule
  ]
})
export class MapModule { }

我在互聯網上研究過,我找到了幾個結果,但我不明白問題出在哪里。

我收到這條消息:

map/map.component.html:2:1 中的錯誤 - 錯誤 NG8001:'app-left-list-container' 不是已知元素:1. 如果 'app-left-list-container' 是一個 Angular 組件,則驗證它是此模塊的一部分。 2. 如果'app-left-list-container' 是一個Web 組件,則將'CUSTOM_ELEMENTS_SCHEMA' 添加到該組件的'@NgModule.schemas' 以抑制此消息。

2 <app-left-list-container></app-left-list-container>
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  map/map.component.ts:5:16
    5   templateUrl: './map.component.html',
                     ~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component MapComponent.

您需要將LeftListModule導入MapModule

問題是,在LeftListModule 中,您確實導出了組件,但在MapModule 中,您沒有導入從中導出組件的模塊。 您需要在第二個模塊的導入中添加LeftListModule

或者

重新定位共享模塊中的共享組件並在兩個導入中添加此共享模塊

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM