简体   繁体   English

在 Angular CLI 中使用 Bootstrap 的最佳方法是什么

[英]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:对我来说最好的方法是:

  • Create a project with ng newng new创建一个项目
  • Install bootstrap, jquery and font-awesome with 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.

相关问题 自定义Bootstrap的最佳方法是什么 - What is the best way to customize Bootstrap 如何使用angular-cli自定义bootstrap 4 - How to customize bootstrap 4 using angular-cli 集成Meteorjs,angular和Bootstrap的最佳方式 - Best way to integrate Meteorjs, angular and Bootstrap 在angular 7中动态html引导程序表中实现排序和过滤的最佳方法是什么? - What is the best way to implement sorting and filtering in a dynamic html bootstrap table in angular 7? 使用 rails 应用程序安装引导程序的最佳方法是什么? - What is the best way to install bootstrap with rails app? 水平对齐bootstrap div的最佳方法是什么? - What is the best way to align bootstrap div horizontally? 使引导程序具有响应能力的最佳方法是什么? - What is the best way to make this responsive in bootstrap? 什么是自定义bootstrap 3.0的最佳方式? - what is the Best way to customize bootstrap 3.0? Ruby on Rails:使用引导程序模式制作注册表的最佳方法是什么? - Ruby on Rails: What is the best way to make a registration form using a bootstrap modal? 可以应用于代码的使用引导程序创建列的最佳方法是什么? - What is the best way of making columns using bootstrap that I can apply to my code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM