虽然还有其他的bootstrap库,如ng-bootstrap专为angular 2而构建.
我想知道两种方法之间有什么区别,可以通过简单的npm install bootstrap在angular 2中使用bootstrap组件,并在angular-cli.json的app脚本中包含它
使用npm包进行bootstrap基本上会添加一些额外的输入绑定来帮助你完成工作.从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.
我个人使用vanilla Bootstrap并包含jquery.我以前读过以避免包含这样的jquery但它还没有给我带来任何问题.但它可能会让一些事情变得困难.我使用标签和可扩展卡时遇到问题.即使使用ng2,我也必须创建布尔值来跟踪它们是否被扩展.
使用它没有任何问题.它可能更好,更安全.
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