在 angular 2 中使用 bootstrap 个组件

using bootstrap components in angular 2

Angular 2个cli可以添加bootstrap js组件并在项目组件中使用它们。

虽然还有其他 bootstrap 库,例如 ng-bootstrap 专门为 angular 构建的 2.

我想知道两种方法之间有什么区别,是否可以通过简单地 npm install bootstrap 在 angular 2 中使用 bootstrap 组件并包含在 angular-cli.json

为 bootstrap 使用 npm 包基本上添加了一些额外的输入绑定来帮助您完成工作。

来自 Reddit

ng-bootstrap gives you Angular input bindings for all the parameters you might need to tweak. If you're just doing the basics then there isn't much difference. But as soon as you need to access a Bootstrap property that isn't controlled by a CSS class, then with vanilla Bootstrap you have to do very un-angularish $(dom-id) references in your Javascript logic, whereas if you're using ng-bootstrap that action is accomplished by tweaking a property that's bound to the ng-bootstrap component.

我个人使用原版 Bootstrap 并包含 jquery。我之前已经阅读过避免像这样包含 jquery 但它还没有给我带来任何问题。但是,这可能会使做一些事情变得困难。我在使用选项卡和可扩展卡片时遇到问题。即使使用 ng2,我也必须创建 booleans 来跟踪它们是否已扩展。

用着没毛病。它可能更好,更安全。

Another pro of using ng version is its light weight because of: * not using jquery

  • readiness to use es2015 modules and lazy loading

  • readiness for tree-shaking to minimize the size

  • being ready to use any bundling type you want

  • template precompiling

在我的项目中,我创建了指令来实例化 jquery+bootstrap 组件。

我的指令具有初始化组件所需的配置处理。