网站搜索

angular - Angular2 模块根模块导入失败


我有三个模块

Appmodule, usersmodule and safetymodule

appmodule 是根模块,我已经在其中导入了 users 和 safety 模块

我也在使用 primeng2 的上下文菜单,这需要我导入

ContextMenuModule

问题出现在 users 模块中,我必须再次导入 context 模块,而我已经在 app 模块中导入过它,如下所示

@NgModule({
  declarations: [
    AppComponent,
  ],
 imports: [
   BrowserModule,
   FormsModule,
   DashboardModule,
   SafetyModule,
   ContextMenuModule, //added this here
   UsersModule,
 ],
 exports: [BrowserModule,ToastyModule,SlimLoadingBarModule,ContextMenuModule],

 bootstrap: [AppComponent]
 })
export class AppModule { }

在用户模块中,当我无法导入 ContextModule 时,会抛出一个错误

我哪里出错了,因为在每个模块中都必须导入模块,这相当于很多重复,我相信 Angular2 的 ngModule 是用来解决这个问题的

我还需要添加什么

更新,这是我添加上下文菜单的方式

   <p-contextMenu  #cm [model]="menuitems"></p-contextMenu>

当我未能在 usersmodule 中导入 ContextMenu 时产生的错误是:

If 'p-contextMenu' is an Angular component and it has 'model' input
 , then verify that it is part of this module.

当我在 users 模块中导入 contextmenu 时,错误被清除了,但我非常担心导入模块的代码重复问题