Bootstrap in angular project

 In this tutorial I will show how to add bootstrap in angular project to and will be using bootstrap css in further tutorial. There are different ways through which bootstrap can be referenced in our angular project

1.Installing Bootstrap from npm using the npm install command, 2.Downloading Bootstrap files and adding them to the src/assets  3.Using Bootstrap from a CDN

  1. Installing Bootstrap from npm using the npm install command : open new terminal->and type “npm install –save bootstrap” . by this command latest bootstrap version will be added inside node_modules/bootstrap , also package reference will be added inside package.json file , apart from this you need to install jQuery by below commands:
1
npm install --save jquery

after installing of above two we need to tell angular cli from where bootstrap referenced should be taken , to do this open angular.json file and add as below :

also in index.html page we can add reference of bootstrap file :

1
2
3
4
5
6
7
8
9
10
11
12
13
<head>
  <meta charset="utf-8">
  <title>Angular Tutorial</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.css">
 
</head>
<body>
  <app-root></app-root>
  <script src="../node_modules/jquery/dist/jquery.js"></script>
  <script src="../node_modules/bootstrap/dist/js/bootstrap.js"></script>   
</body>

another option is to import bootstrap.css in our styles.css file : open src/styles.css and add below line:

1
@import "~bootstrap/dist/css/bootstrap.css"

In this tutorial I have used first approach . you can use whatever you like. let put below code in our app.component.html ,save and see our default page , how does it look like.

And our screen looks as below :

thats it. In this tutorial we learnt how to add bootstrap reference and use in our angular project. In next tutorial we are going to design employee form using bootstrap.

Comments

Popular posts from this blog

Angular Project structure and default component

Create Angular project step by step