简体   繁体   English

ng-bootstrap是否正在导入所有组件

[英]Is ng-bootstrap importing all the components

I'm new in ng-boostrap and followed their getting started guide. 我是ng-boostrap的新手,并按照他们的入门指南进行操作。 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? 即使我不使用ng-bootstrap,它也会导入ngb-carousel,ngb-progressbar等所有组件吗?

There's another bootstrap library, ngx-bootstrap that does importing each of the components like this 还有另一个引导程序库ngx-bootstrap确实会像这样导入每个组件

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. 您只能直接导入您感兴趣的模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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