Categories: angular

Bootstrap Installation in Angular

Bootstrap is world’s most popular front-end component library.

You can build responsive, mobile-first projects on the web with the bootstrap.

Bootstrap is an open source toolkit for developing web applications using HTML, CSS, and JS.

Quickly prototype your ideas or build your entire app with bootstrap Sass variables and mixins, responsive grid system, extensive prebuilt components, and powerful plugins built on jQuery.

Using bootstrap you can quickly develop Angular front-end UI.

So let’s see the ways, to use bootstrap in angular application

There are two ways to use bootstrap in an angular application.

  • Using Bootstrap CDN
  • Installing Bootstrap libraries in Angular Application.

Bootstrap CDN is an easy and quick way to use bootstrap in your application.

You just need to add below CSS and JS files in index.html of Angular application

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>

Generally, this is a good way, if your application is running on the internet and if it is allowed to use external CSS and Scripts in your organization.

But if either of above is not valid then you need to install bootstrap in your application, after downloading the npm modules.

To install bootstrap in your Angular CLI application run below command in your project directory.

npm install --save bootstrap@4.0.0-beta.3

For the latest stable version installation run below command

npm install --save bootstrap

Note :

--save in npm install command will also make entry of bootstrap@4.0.0-beta.3 in the package.json

After executing above command you will get below result.

Bootstrap is dependent on jQuery and Popper.js library, so if you have not installed jquery and popper.js before in your application, then you need to also install this two libraries.

To install jQuery in your application, execute below command

npm install --save jquery

and to install popper.js, execute below command

npm install --save popper.js

For Angular 6+ project generated using Angular CLI 6+,  include following .css file in the styles array property of angular.json

Note : In Angular CLI 6+, angular-cli.json is replaced with angular.json

"styles": [
        "src/styles.css",
        "node_modules/bootstrap/dist/css/bootstrap.min.css"
      ],

As well as, include following .js files in the scripts array property of angular.json

"scripts": [
"node_modules/jquery/dist/jquery.slim.min.js",
"node_modules/popper.js/dist/umd/popper.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js"
 ],

For Angular 5 or lower version application, include following .css file in the styles array property of .angular-cli.json

"styles": [
        "styles.css",
        "../node_modules/bootstrap/dist/css/bootstrap.min.css"
      ],

As well as, include following .js files in the scripts array property of .angular-cli.json

"scripts": [
"../node_modules/jquery/dist/jquery.slim.min.js",
"../node_modules/popper.js/dist/umd/popper.min.js",
"../node_modules/bootstrap/dist/js/bootstrap.min.js"
 ],

Now serve the application using ng serve command. You can see in the below output, fonts of headers and text are changed.

As shown below, Bootstrap is successfully installed, now you can build User Interface using bootstrap component.

Ankit

Disqus Comments Loading...

Recent Posts

Awesome Charts in Angular 13 with ng2-charts

Charts help us to visualize large amounts of data in an easy-to-understand and interactive way.  …

2 years ago

Client-Side PDF Generation In Angular 13 With PDFMake

Generating reports, invoices, blog content, documents, guidelines, forms, etc in PDF form is a common…

2 years ago

Dynamically Add Title and Meta Tags on Route Change in Angular

Web Page title, description, and other meta tags are very important for the Search Engine…

4 years ago

Integrate Google Analytics with Angular | Angular SEO

Google Analytics is a popular analytical tool for web and mobile applications from Google. It…

4 years ago

16 Best Chrome DevTools Tips and Tricks

Chrome DevTools provides amazing features to debug source code, capture element state, update and test…

4 years ago

Data Visualization with ECharts in Angular using ngx-echarts

Angular Charts Series Articles Best Angular Chart Libraries How to use ngx-charts in angular application…

4 years ago