Angular 带多个模块的嵌套角度组件(Jhipster)

Angular 带多个模块的嵌套角度组件(Jhipster),angular,module,components,jhipster,Angular,Module,Components,Jhipster,假设我在我的应用程序中有两个模块(比如父组件和子组件),每个模块都有自己的组件,我想在父组件中显示一个子组件 我尝试在子模块中导出子组件,然后在父模块中导入它 成功了!子组件显示在我的父组件中 但我有一个问题,那就是我的子组件是两个模块的一部分! 这就是我试图显示任何子组件的时候 如果有人能帮上忙的话,我会很忙的 在我将子模块移动到app.module之后,这就是我的模块 子模块: import { NgModule } from '@angular/core'; import { Router

假设我在我的应用程序中有两个模块(比如父组件和子组件),每个模块都有自己的组件,我想在父组件中显示一个子组件

我尝试在子模块中导出子组件,然后在父模块中导入它 成功了!子组件显示在我的父组件中

但我有一个问题,那就是我的子组件是两个模块的一部分! 这就是我试图显示任何子组件的时候 如果有人能帮上忙的话,我会很忙的

在我将子模块移动到app.module之后,这就是我的模块

子模块:

import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

import { WinpharmSharedModule } from 'app/shared/shared.module';
import { StockComponent } from './stock.component';
import { StockDetailComponent } from './stock-detail.component';
import { StockUpdateComponent } from './stock-update.component';
import { StockDeletePopupComponent, StockDeleteDialogComponent } from './stock-delete-dialog.component';
import { stockRoute, stockPopupRoute } from './stock.route';

const ENTITY_STATES = [...stockRoute, ...stockPopupRoute];

@NgModule({
  imports: [WinpharmSharedModule, RouterModule.forChild(ENTITY_STATES)],
  declarations: [StockComponent, StockDetailComponent, StockUpdateComponent, StockDeleteDialogComponent, StockDeletePopupComponent],
  entryComponents: [StockComponent, StockUpdateComponent, StockDeleteDialogComponent, StockDeletePopupComponent]
})
export class WinpharmStockModule {}
父模块:

import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

import { WinpharmSharedModule } from 'app/shared/shared.module';
import { ProduitComponent } from './produit.component';
import { ProduitDetailComponent } from './produit-detail.component';
import { ProduitUpdateComponent } from './produit-update.component';
import { ProduitDeletePopupComponent, ProduitDeleteDialogComponent } from './produit-delete-dialog.component';
import { produitRoute, produitPopupRoute } from './produit.route';

const ENTITY_STATES = [...produitRoute, ...produitPopupRoute];

@NgModule({
  imports: [
    WinpharmSharedModule,
    RouterModule.forChild(ENTITY_STATES)
  ],
  declarations: [
    ProduitComponent,
    ProduitDetailComponent,
    ProduitUpdateComponent,
    ProduitDeleteDialogComponent,
    ProduitDeletePopupComponent
  ],
  entryComponents: [ProduitComponent, ProduitUpdateComponent, ProduitDeleteDialogComponent, ProduitDeletePopupComponent]
})
export class WinpharmProduitModule {}
然后app.module.ts:

import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
...
import { WinpharmStockModule } from './entities/stock/stock.module';

@NgModule({
  imports: [
    BrowserModule,
    NgbModule,
    // Here's the child module
    WinpharmStockModule,
    WinpharmSharedModule,
    WinpharmCoreModule,
    WinpharmHomeModule,
    // jhipster-needle-angular-add-module JHipster will add new module here
    WinpharmEntityModule,
    WinpharmAppRoutingModule
  ],
  declarations: [...
})
export class WinpharmAppModule {}
错误:“未捕获(承诺中)错误:类型<强>子组件是2个模块声明的一部分:<强> ChildModule < /Stand >和<强> PARDEMODE !请考虑将<强>子组件导入到一个更高的模块中,该模块导入<强> PARTEMODE < <强> > <强> ChildModule > /强>。还可以创建一个新的NGMULTLE模块,导出s并包括ChildComponent,然后在ParentModuleChildModule中导入该模块


答案在错误消息中。您只需要在模块/组件层次结构中导入组件一次。然后您就可以在所有子模块/组件中访问它。因此,在您的情况下,请在父模块中声明它,而不是在子模块中声明它,或者按照第二部分中的说明执行message@JSmith问题是我不知道d和他们说的一样,但是我有更多的错误,但是我会再试一次,谢谢你的关心。只要把你按照他们告诉你的那样做时遇到的错误放在你的帖子里。如果我现在不能从父模块中删除导入,并将其移动到app.module.ts,我会很乐意提供帮助。不过同样的问题还是谢谢你,我会明白的如果有一些无用的声明,那么我可以将模块添加到我的问题中