[英]What is the best way for using Bootstrap in Angular CLI
Which one is the best practice to use Bootstrap in Angular-Cli Project?在 Angular-Cli 项目中使用 Bootstrap 的最佳实践是哪一种?
Using this method: https://medium.com/@beeman/tutorial-add-bootstrap-to-angular-cli-apps-b0a652f2eb2使用这种方法: https : //medium.com/@beeman/tutorial-add-bootstrap-to-angular-cli-apps-b0a652f2eb2
Or或者
Using ngx-bootstrap: https://github.com/valor-software/ngx-bootstrap/blob/development/docs/getting-started/ng-cli.md使用 ngx-bootstrap: https : //github.com/valor-software/ngx-bootstrap/blob/development/docs/getting-started/ng-cli.md
The best way for me is:对我来说最好的方法是:
ng new
ng new
创建一个项目npm install bootstrap@4.0.0-alpha.6 jquery font-awesome
npm install bootstrap@4.0.0-alpha.6 jquery font-awesome
安装 bootstrap、jquery 和npm install bootstrap@4.0.0-alpha.6 jquery font-awesome
in your .angular-cli.json
add:在你的
.angular-cli.json
添加:
"apps": [{ "styles": [ "styles.css", "../node_modules/bootstrap/dist/css/bootstrap.min.css", "../node_modules/font-awesome/css/font-awesome.min.css" ], "scripts": [ "../node_modules/jquery/dist/jquery.min.js", "../node_modules/bootstrap/dist/js/bootstrap.min.js" ]
This will automatically compile the bootstrap css and javascript, font-awesome and jquery, which is required by the bootstrap js, in your index.html.这将在您的 index.html 中自动编译 bootstrap css 和 javascript、font-awesome 和 jquery,这是 bootstrap js 所需的。
Note : The jquery.min.js
under scripts must be included before the bootstrap.min.js
is included, because bootstrap.min.js
requires jquery.min.js
to work properly.注意:
jquery.min.js
下的jquery.min.js
必须在bootstrap.min.js
包含之前包含,因为bootstrap.min.js
需要jquery.min.js
才能正常工作。
UPDATE: Bootstrap 4 requires tether.js.更新: Bootstrap 4 需要 tether.js。 Install it with
npm install tether
and add it to your scripts in .angular-cli.json
BEFORE bootstrap.min.js.使用
npm install tether
安装它,并在 bootstrap.min.js 之前将其添加到.angular-cli.json
脚本中。
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/tether/dist/js/tether.min.js",
"../node_modules/bootstrap/dist/js/bootstrap.min.js"
Prefer using ng-bootstrap
to bootstrap
in any angular project.更喜欢使用
ng-bootstrap
在任何角度项目中bootstrap
。
Below is a comment taken from documentation .以下是来自文档的评论。
The goal of ng-bootstrap is to completely replace JavaScript implementation for components. ng-bootstrap 的目标是完全替代组件的 JavaScript 实现。 Nor should you include other dependencies like jQuery or popper.js.
您也不应该包含其他依赖项,例如 jQuery 或 popper.js。 It is not necessary and might interfere with ng-bootstrap code.
这不是必需的,可能会干扰 ng-bootstrap 代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.