Skip to content
  • Home
  • Search
  • Tools
  • About
  • Terms of Service Agreement
  • Log In
  • Guest

Angular: Bootstrap Install Strategies

Posted on January 20, 2021March 13, 2021 By Andre Dias
angular, bootstrap

 

Some alternatives to install bootstrap:

– manual install plus jquery via npm,
– via bootstrap’s npm install plus jquery,
– via bootstrap’s npm install plus ngx-bootstrap (with or without jquery install) or
– via bootstrap’s npm install plus ng-bootstrap (with or without jquery install).

The alternatives are tested using then code of the “Album” template from Bootstrap (image above).

This post goes step-by-step through the first three options, and the forth follows the third.

At the of the text, there is a one-step routine for installing bootstrap/ngx env.
I think it as a summary — the daily routine to set bootstrap in an angular project.

(to reach there faster, press the button of “table of contents”, below)

 

Table of Contents

    • ABOUT
  • #METHOD 1 – MANUAL INSTALL
        • Download Code at GitHub
  • METHOD 2 – USING NPM INSTALLER
    • Download Code at GitHub
  • OBSERVATION
  • *IMPORTANT NOTE:
  • METHOD 3 – USING NGX-BOOTSTRAP
        • Download Code at GitHub
  • SUMMARY FOR DAILY TASKS
  • ADDITIONAL SOURCES

ABOUT

1. It is just considered here the “npm” installer.
Please, choose your own, since the results are equivalent.

2. “ngx-bootstrap” and “ng-bootstrap” are both libraries to enable bootstrap features that would require JQuery, but without the need of explicitly installing it.

Transcribing this snippet of comment from Stack Overflow for the sake of our comfort:

I’ve used both ngx-bootstrap(by Valor) and ng-bootstrap(by ng-boostrap). Here are my two cents of the unique features you get from them:

ngx-bootstrap:

  1. Builtin animation support on almost everything (modals, accordion, collpase, dropdown, datepicker…)
  2. Better Modal support (nested modals, modal as a service, modal as a template)
  3. Sortable Component (with Drag&Drop Feature)

ng-bootstrap:

  1. Nav Feature (Tabset has been made deprecated)
  2. Builtin Toast component
  3. Package size is almost half times as ngx-bootstrap (Minified + Gzipped)

You can also compare between their npm download counts with npmtrends.

[Note: My answer is based current latest version i.e ngx-bootstrap v5.5.0 and ng-boostrap v6.0.0]

edited Feb 25 ’20 at 12:12
answered Feb 25 ’20 at 12:05
Imtiaz Shakil Siddique

What is the difference between “ng-bootstrap” and “ngx-bootstrap”?

 

Alternative site in portuguese:
the difference between ng-bootstrap and ngx-bootstrap (portuguese)

 

 

#METHOD 1 – MANUAL INSTALL

1. Download bootstrap:

– latest version:
getbootstrap.com/

– prior versions:
v.3.3
v.3.3.7
v.4.5


2. Extract to style dir:

mkdir styles
xcopy …\bootstrap-4.5.3-dist ..\PROJECT_ROOT\src\styles /Y/S/I/E

 

3. Import the CSS.

Two alternatives:

3a. Edit “angular.json” and set:

	"styles": [
		"src/styles.css",
		"src/styles/bootstrap-4.5.3-dist/css/bootstrap.css",
	],

 

or

3b. Use import:
@import ‘./styles/bootstrap-5.0.0-beta1-dist/css/bootstrap.min.css’;


4. If desired jquery, do:

npm install jquery popper.js –save

Edit angular.json and set:

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

 

***IMPORTANT NOTE:

Avoid using CSS resources under assets directory.
When deploying to the production using Angular CLI, the CSS files registered in angular.json are minified and bundled into a single styles.css.
The assets folder is copied to the dist folder during the build process then, the CSS code get duplicated.
Only place CSS files under assets if importing them directly in the index.html.

 

Download Code at GitHub

 

METHOD 2 – USING NPM INSTALLER

 

1. Install bootstrap using npm:

  • For Bootstrap 3:

    npm install bootstrap@3.3.7

  • For Bootstrap 4:

    npm install bootstrap@4.5.3

  • For latest Bootstrap version: npm install bootstrap


2. Import the CSS.

Edit “angular.json” and set:

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

3. If desired jquery, do:

npm install jquery popper.js –save


Edit angular.json and set:

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

NOTE: you join install commands:
npm install bootstrap@4.5.3 jquery popper.js –save

 

Download Code at GitHub

OBSERVATION

Personally, I do not use the “@import” annotation. Something like this:

@import “../../../node_modules/bootstrap/dist/css/bootstrap.min.css”;

The configuration when is set in “angular.json” file is a much better option.

 

*IMPORTANT NOTE:

Don’t use the assets directory to set the CSS files. When deploying to the production using Angular CLI, the CSS files registered in angular.json are minified and bundled into a single styles.css. The assets folder is copied to the dist folder during the build process then, the CSS code get duplicated. Only place CSS files under assets if importing them directly in the index.html.

 

METHOD 3 – USING NGX-BOOTSTRAP

 


1. Please, perform the same routine used for method 1 or 2.


2. Install ngx-bootstrap.

npm install ngx-bootstrap –save
or
npm i ngx-bootstrap

NOTES:

a. ng2-bootstrap is the errlier name for ngx-bootstrap.

b. Any doubt about the differences between the commands above?
For this example, using npm 6.X, they are equivalents.

More information?
Specifying dependencies and devDependencies in a package.json file
What is the –save option for npm install?

c. The installation may returns some warns like this:
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: …

Go ahead.
If desired, follow its instructions. Example:
found 4 vulnerabilities (3 low, 1 high)
run `npm audit fix` to fix them, or `npm audit` for details
Be prepared, “audit fix” may take some time.

3. Decide the components you wish to use.

Check ngx-bootstrap documentation.

Following the documentation, pick your choices.

4. Next, an example with dropdowns.
Go to the dropdown documentation page.

The documentation shows the configuration required (italic).

5. Edit app.module.ts and set the imports.
Example:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
// RECOMMENDED
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
// NOT RECOMMENDED (Angular 9 doesn't support this kind of import)
//import { BsDropdownModule } from 'ngx-bootstrap';


@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    BsDropdownModule.forRoot(),
    BrowserAnimationsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

NOTES:

a. The .forRoot() method loads each module making available all resources.

b. Alternatively, imports may be declared in a specific module if desired.

 

6. Adding the dropdown button to the html page.
Edit “app.component.html” and add an extra row to get a better visualization.

	...
	<div class="container">
		<div class="row" style="margin-bottom: 40px;">
			<div class="col-md-12">
			</div>
		</div>

 

7. Copy the code from the documentation inside the new row:

	<div class="btn-group" dropdown>
	  <button id="button-basic" dropdownToggle type="button" class="btn btn-primary dropdown-toggle"
			  aria-controls="dropdown-basic">
		Button dropdown <span class="caret"></span>
	  </button>
	  <ul id="dropdown-basic" *dropdownMenu class="dropdown-menu"
		  role="menu" aria-labelledby="button-basic">
		<li role="menuitem"><a class="dropdown-item" href="#">Action</a></li>
		<li role="menuitem"><a class="dropdown-item" href="#">Another action</a></li>
		<li role="menuitem"><a class="dropdown-item" href="#">Something else here</a></li>
		<li class="divider dropdown-divider"></li>
		<li role="menuitem"><a class="dropdown-item" href="#">Separated link</a>
		</li>
	  </ul>
	</div>

 

8. Set inside the “div column”:

	<div class="row" style="margin-bottom: 40px;">
		<div class="col-md-12">
			<div class="btn-group" dropdown>
			  <button id="button-basic" dropdownToggle type="button" class="btn btn-primary dropdown-toggle"
					  aria-controls="dropdown-basic">
				Button dropdown <span class="caret"></span>
			  </button>
			  <ul id="dropdown-basic" *dropdownMenu class="dropdown-menu"
				  role="menu" aria-labelledby="button-basic">
				<li role="menuitem"><a class="dropdown-item" href="#">Action</a></li>
				<li role="menuitem"><a class="dropdown-item" href="#">Another action</a></li>
				<li role="menuitem"><a class="dropdown-item" href="#">Something else here</a></li>
				<li class="divider dropdown-divider"></li>
				<li role="menuitem"><a class="dropdown-item" href="#">Separated link</a>
				</li>
			  </ul>
			</div>
		</div>
	</div>

 

9. Start the server.
cd $PROJECT_ROOT
ng serve

 

10. Point on browser:
http://localhost:4200/

 

Download Code at GitHub

SUMMARY FOR DAILY TASKS

This procedure installs: bootstrap , jquery, popper and  ngx-bootstrap.

1. Install:
npm install bootstrap jquery popper.js ngx-bootstrap –save

2a. Edit “angular.json” and set:

“styles”: [
“src/styles.css”,
“node_modules/bootstrap/dist/css/bootstrap.css”
],
“scripts”: [
“node_modules/jquery/dist/jquery.js”,
“node_modules/popper.js/dist/umd/popper.js”,
“node_modules/bootstrap/dist/js/bootstrap.js”
]

*** IMPORTANT:
If the angular project was created with other option than CSS, you must set the extension of style files.
Example: if using SCSS, switch to:
“node_modules/bootstrap/dist/css/bootstrap.scss”

3. Edit app.module.ts and set the imports.
Example:
@FROM: https://valor-software.com/ngx-bootstrap/#/dropdowns

import { BrowserModule } from ‘@angular/platform-browser’;
import { NgModule } from ‘@angular/core’;
import { AppComponent } from ‘./app.component’;

import { BrowserAnimationsModule } from ‘@angular/platform-browser/animations’;
// RECOMMENDED
import { BsDropdownModule } from ‘ngx-bootstrap/dropdown’;
// NOT RECOMMENDED (Angular 9 doesn’t support this kind of import)
//import { BsDropdownModule } from ‘ngx-bootstrap’;

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BsDropdownModule.forRoot(),
BrowserAnimationsModule
],
providers: [],
bootstrap: [AppComponent] })
export class AppModule { }

 

4. Check ngx features and configuration at:
https://valor-software.com/ngx-bootstrap/

 

5. Mini code to test the env:

<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
	<a class="navbar-brand" href="#">Navbar</a>
	<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
		<span class="navbar-toggler-icon"></span>
	</button>
	<div class="collapse navbar-collapse" id="navbarsExampleDefault">
		<ul class="navbar-nav mr-auto">
			<li class="nav-item active">
				<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
			</li>
			<li class="nav-item">
				<a class="nav-link" href="#">Link</a>
			</li>
			<li class="nav-item">
				<a class="nav-link disabled" href="#">Disabled</a>
			</li>
			<li class="nav-item dropdown">
				<a class="nav-link dropdown-toggle" href="http://example.com" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
				<div class="dropdown-menu" aria-labelledby="dropdown01">
					<a class="dropdown-item" href="#">Action</a>
					<a class="dropdown-item" href="#">Another action</a>
					<a class="dropdown-item" href="#">Something else here</a>
				</div>
			</li>
		</ul>
		<form class="form-inline my-2 my-lg-0">
			<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
			<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
		</form>
	</div>
</nav>
<!-- Main jumbotron for a primary marketing message or call to action -->

 

 

ADDITIONAL SOURCES

ngx-bootstrap npmjs doc

ngx-bootstrap home

ngx bootstrap | With Bootstrap 3 and 4

How to Add Bootstrap to an Angular CLI project

 

Andre Dias
Andre Dias

Brazilian system analyst graduated by UNESA (University Estácio de Sá – Rio de Janeiro). Geek by heart.

Post navigation

❮ Previous Post: Git: Rebase – When and Where Not To Do
Next Post: JavaScript: Svelte — A Little Guide to Start Studying This Interesting Framework ❯

Search

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
angular
bootstrap
browser
computer science
container
data persistence
database
devops
editors
hardware
health
hosting
info
internet
it
java
javascript
network
node.js
play
protocol
security
self-help
selfhelp
server
services
soft
software engeneering
sql
support
Systems
techs
Uncategorized
versioning
web
web design
windows
wordpress

Recent Posts

  • Angular From Scratch Tutorial – Step 9: Modal
  • Angular From Scratch Tutorial – Step 8: Miscellany
  • Angular From Scratch Tutorial – Index
  • angular: Reading JSON files
  • NODE.JS: SEQUELIZE: MVC Project – 4TH STEP

Categories

  • angular (19)
  • bootstrap (6)
  • browser (4)
  • computer science (4)
  • container (1)
  • data persistence (2)
  • database (11)
  • devops (1)
  • editors (1)
  • hardware (4)
  • health (2)
  • hosting (1)
  • info (1)
  • internet (2)
  • it (1)
  • java (13)
  • javascript (32)
  • network (6)
  • node.js (1)
  • play (1)
  • protocol (1)
  • security (4)
  • self-help (1)
  • selfhelp (1)
  • server (2)
  • services (1)
  • soft (1)
  • software engeneering (1)
  • sql (1)
  • support (2)
  • Systems (1)
  • techs (3)
  • Uncategorized (2)
  • versioning (6)
  • web (1)
  • web design (5)
  • windows (3)
  • wordpress (4)

Copyright © 2025 .

Theme: Oceanly by ScriptsTown

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT