Declaring multiple components within @ngModule in Angular 2

前端 未结 2 1176
花落未央
花落未央 2021-01-06 02:24

I am developing a large application using Angular 2 and ASP.net MVC. I have approximately 120 components in my application which are all declared i

2条回答
  •  [愿得一人]
    2021-01-06 03:13

    You can build a shared module and add the components to this module, then you only have to add the shared module to imports: [MySharedModule] and all components and directives exported by MySharedModule become available to the importing module.

    @NgModule({
      imports: [ CommonModule ],
      declarations: [ Component1,   Component2,   Component3....      Component120 
    ],
      exports: [ Component1,   Component2,   Component3....      Component120 ],
    })
    

    export class MySharedModule {}

    @NgModule({
      declarations: [AppComponent],
      bootstrap: [AppComponent],
      imports: [BrowserModule, MySharedModule]
    })
    class AppModule {}
    

提交回复
热议问题