Skip to content
the poor coder

how to add bootstrap in angular cli

Poor Man
Published
Reading time
2 min read
On this page

How to Add Bootstrap in Angular CLI#

Introduction#

Bootstrap is a widely-used CSS framework that makes it easy to create responsive and attractive web pages. Angular CLI is a command-line interface that simplifies the process of creating and managing Angular applications. In this blog post, we will explore how to add Bootstrap to an Angular CLI project.

Step-by-Step Guide#

  1. First, we need to install Bootstrap as a dependency in our project. We can do this using the following command in our terminal:
Bash
npm install bootstrap
  1. Once the installation is complete, we need to import the Bootstrap CSS and JavaScript files into our project. We can do this by adding the following lines to the styles and scripts arrays in our .angular-cli.json file:
JSON
"styles": [
    "styles.css",
    "../node_modules/bootstrap/dist/css/bootstrap.min.css"
  ],
  "scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/bootstrap/dist/js/bootstrap.min.js"
  ]
  1. Finally, we need to tell Angular CLI to include these files when building our project. We can do this by adding the following line to the assets array in our .angular-cli.json file:
JSON
{
    "glob": "**/*",
    "input": "../node_modules/bootstrap/dist/fonts",
    "output": "./fonts/"
}
  1. Save the changes to the .angular-cli.json file and restart the development server using the following command in our terminal:
Bash
ng serve

Alternative Methods#

  • You can also use the Angular Bootstrap library (ng-bootstrap) instead of the regular Bootstrap library. This library provides Angular-specific components that are easier to use and integrate with your Angular project. You can install it using the following command:
Bash
npm install --save @ng-bootstrap/ng-bootstrap
  • If you prefer to use a CDN instead of downloading the Bootstrap files, you can add the following lines to your index.html file:
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

Conclusion#

By following these steps, you should now have Bootstrap up and running in your Angular CLI project. Whether you choose to use the regular Bootstrap library or the ng-bootstrap library, you can now easily add attractive and responsive UI elements to your Angular applications.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC