Learn Efficient Ways To Install Bootstrap In Your Angular Project

Hey Developers, I am sure you already read my previous article about Why Developers choose Angular and hope that helped you to understand.
 
Now, we are moving ahead and by the end of this tutorial you will have learned the concepts listed below:
  1. How to create a new directory using the command,
  2. How to create a new Angular project,
  3. How to add style while creating a new Angular project
  4. How to Install NPM
  5. How to run the Angular project
  6. How to install Bootstrap files
  7. How to create a navigation bar in the Angular project
Refer to my article Prerequisites to Create a new Angular project before creating an Angular project.
 
Steps to create a new Angular project,
 
Step 1
 
Open command prompt & create a new directory with the below command shown in the screenshot 
 
Learn Efficient Ways To Install Bootstrap In Your Angular Project
 
Check your D: drive and the csharpcorner folder will be created.
 
Step 2
 
Now go ahead and create a new Angular project with the below command:
 
Learn Efficient Ways To Install Bootstrap In Your Angular Project
 
We are creating a new Angular application with ng new command and the application name in TaskManager. Now we  are required to specify style options whether we want to use CSS, SASS, SCSS, etc. If you look at our command above we are using -style=scss command to add the styles. In order to add the routing to our application we need to give --routing as shown above. When the application is created it will try to install all npm packages, so to skip those installations we have to add --skip-install text in our command.
 
So our final command looks like below:
 
command: ng new TaskManager --style=scss --routing --skip-install 
 
You can check your csharpcorner folder and see the application is created, it looks like below.
 
Learn Efficient Ways To Install Bootstrap In Your Angular Project
 
Install NPM Packages by running the below command, this will install the essential packages to run the Angular application.
 
npm install
 
Now open the folder in Visual Studio Code,
 
Learn Efficient Ways To Install Bootstrap In Your Angular Project
 
Now go back to command prompt and type this command ng serve --open, the default port number for angular is 4200, we can also change the default port by using this command and hit enter.
 
ng serve --open --port=8112
 
Learn Efficient Ways To Install Bootstrap In Your Angular Project
 
Learn Efficient Ways To Install Bootstrap In Your Angular Project
So far, we have learned,
  • Creating a new Angular project with SCSS style,
  • Installing NPM packages,
  • Run the application by changing the default port number explicitly. 
Now, let' see how we can install Bootstrap in our new brand angular project
 
Install jquery package because bootstrap works on jquery, run this command in the command prompt,
 
npm install jquery --save 
 
Next, install another package called popper.js, so the command is,
 
npm install popper.js --save
 
Now install the actual package called bootstrap, this package will load CSS files/javascript files of bootstrap.
 
npm install bootstrap --save
 
Additionally, in our article, we shall use font-awesome which provides a large set of icons,
 
npm install font-awesome --save
 
After installing all the above, we have to add these files in angular.json file in styles and scripts components as shown below,
 
Learn Efficient Ways To Install Bootstrap In Your Angular Project
 
Now we have loaded essential CSS/javascript files that are required to run bootstrap.
 
Go back to the command prompt, stop the ng serve command by pressing cntrl+c twice and run the ng serve --open command again 
 
Result before adding bootstrap files
 
Learn Efficient Ways To Install Bootstrap In Your Angular Project
Results after adding bootstrap files
 
Learn Efficient Ways To Install Bootstrap In Your Angular Project
Finally, we are done adding bootstrap files to our Angular project. Now let me show you how to add a Navigation bar to our new brand angular application. Get "app.component.html" and create nav tag and the below code in the nav tag,
  1. <nav class="navbar navbar-expand-sm bg-success navbar-dark">  
  2.     <a class="navbar-brand" href="#">  
  3. Angular Task Manager  
  4. </a>  
  5.     <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#mynav">  
  6.         <span class="navbar-toggler-icon"></span>  
  7.     </button>  
  8.     <div class="collapse navbar-collapse" id="mynav">  
  9.         <ul class="navbar-nav mr-auto">  
  10.             <li class="nav-item">  
  11.                 <a class="nav-link" href="#">Dashboard</a>  
  12.             </li>  
  13.             <li class="nav-item">  
  14.                 <a class="nav-link" href="#">About</a>  
  15.             </li>  
  16.         </ul>  
  17.         <form class="form-inline my-2 my-lg-0">  
  18.             <div class="input-group">  
  19.                 <div class="input-group-prepend">  
  20.                     <span class="input-group-text" id="search">  
  21.                         <i class="fa fa-search"></i>  
  22.                     </span>  
  23.                 </div>  
  24.                 <input type="text" class="form-control" placeholder="Search">  
  25.                 </div>  
  26.                 <button class="btn btn-warning my2- my-sm-0" type="button">Search</button>  
  27.             </form>  
  28.         </div>  
  29.     </nav>  
Screenshot reference
 
Now go back to command prompt window and run ng serve --open command again to see the result as below with maximized window,
 
Learn Efficient Ways To Install Bootstrap In Your Angular Project
 
With minimized window,
 
Learn Efficient Ways To Install Bootstrap In Your Angular Project
 

Conclusion

 
In this article, we learned,
  1. How to create a new directory using the command
  2. How to create a new Angular project
  3. How to add style while creating a new angular project
  4. How to Install NPM
  5. How to run the Angular project
  6. How to install Bootstrap files
  7. How to create a navigation bar in the Angular project 
Would you tell us how you feel about this article?
 
Happy Coding :)