Declaring multiple components within @ngModule in Angular 2

前端 未结 2 1165
花落未央
花落未央 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 {}
    
    0 讨论(0)
  • 2021-01-06 03:13

    I'm afraid there is not a shorter way to achieve what you are trying to do.

    But if it is possible, you can divide your application in multiple parts. This means you will have more than one app.module.ts.

    0 讨论(0)
提交回复
热议问题