简体   繁体   中英

Is ng-bootstrap importing all the components

I'm new in ng-boostrap and followed their getting started guide. Here's the important part of the code.

import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
 ...

@NgModule({

  imports:      [ 
   NgbModule.forRoot(),
    ...
   ],

Is ng-bootstrap importing all the components like ngb-carousel, ngb-progressbar and etc even though I'm not using it?

There's another bootstrap library, ngx-bootstrap that does importing each of the components like this

import { ModalModule } from 'ngx-bootstrap/modal';
@NgModule({
  imports: [ModalModule.forRoot(),
   ...]
})
export class AppModule(){}

which is also how you import components modules similar in angular material

Can anyone shed some light on this?

Yes, it imports all components. You can see it here :

@NgModule({
  imports: [
    NgbAlertModule.forRoot(), NgbButtonsModule.forRoot(), ...
  ],
  exports: NGB_MODULES
})
export class NgbRootModule {
}

@NgModule({imports: NGB_MODULES, exports: NGB_MODULES})
export class NgbModule {
  static forRoot(): ModuleWithProviders { return {ngModule: NgbRootModule}; }
}

It's probably done for convenience. Since individual modules are exported as well:

export {
  NgbAccordionModule,
  NgbPanelChangeEvent,
  ...

You can import directly only the modules you're interested in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM