How to Integrate Bootstrap with Angular (Angular 6)

Bootstrap is a web development framework for more faster and easier that includes HTML and CSS based responsive design templates. So in the tutorial, we show how to integrate Bootstrap with Angular project.

Related posts:
How to Integrate Angular 6 & SpringBoot 2.0 RestAPI – SpringToolSuite
Angular NgFor Repeater Directive – Loop over a Collection (Angular 6)

Technologies

  • Node.js – version v10.4.0
  • Angular – version 6
  • Bootstrap – 3.x & 4.x
  • Visual Studio Code – version 1.24.0

Goal

After tutorial, we can integrate Bootstrap to Angular project.

-> Project structure:

Angular-6-Bootstrap + Project-Structure

-> results:

Angular-6-Bootstrap + integrate-results

Integrate Bootstrap with Angular project

We have 3 approaches:

  • Include Bootstrap from CDN
  • Include Local Bootstrap
  • Install Bootstrap via NPM
Preparation

– Create an Angular project:

Angular-6-Bootstrap + Create-Angular-Project

– Generate 3 components {BootstrapJumbotron, BootstrapTable, BootstrapModel}

Angular-6-Bootstrap + Generate-Angular-Components

Change AppComponent template file app.component.html as below:

Include Bootstrap from CDN
Bootstrap 3

Include Bootstrap 3 Style & JQuery Script from CDN (Content Delivery Network) to ‘index.html’ file.

-> Details:

Bootstrap 4

Include Bootstrap 4 Style & JQuery Script from CDN (Content Delivery Network) to ‘index.html’ file.

-> Details:

Include Local Bootstrap

Please follow below links to download Bootstrap:

Create bootstrap folder under /src folder, then add bootstrap-4.1.1-dist with Bootstrap 4 (or bootstrap-3.3.7-dist with Bootstrap 3).

Download JQuery at link: jquery-3.3.1.min.js. Then create a jquery folder under /src folder -> Add jquery-3.3.1.min.js file to it:

Angular-6-Bootstrap + add-bootstrap-jquery-folders

Configure Bootstrap & JQuery in angular.json file:

Install Bootstrap via NPM

Use NPM to download Bootstrap & JQuery. Bootstrap and jQuery will be installed into the node_modules folder.

– With Bootstrap 3, use cmd:

– With Bootstrap 4, use cmd:

Configure installed Bootstrap & JQuery in angular.json file:

Bootstrap Code
Bootstrap Jumbtron

In BootstrapJumbotronComponent component, modify template bootstrap-jumbotron.component.html file with jumbotron class:

Bootstrap Table

In BootstrapTableComponent component, modify bootstrap-table.component.ts class as below:

Then use Bootstrap table class to modify template file bootstrap-table.component.html :

Bootstrap Modal

In BootstrapModalComponent component, modify template bootstrap-modal.component.html file as below:

Run & Check Results

Run above Angular project by cmd: ng serve --open

Angular-6-Bootstrap + integrate-results

-> Open Modal:

Angular-6-Bootstrap + integrate-results-modal

SourceCode

How to run the below sourcecode:

-> Source Code:

Integrate-Angular-Bootstrap

By JavaSampleApproach | June 21, 2018.

Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*