Using Bootstrap with Angular 2


https://i.ytimg.com/vi/OrH90MiFthM/hqdefault.jpg



Text version of the video
http://csharp-video-tutorials.blogspot.com/2017/08/using-bootstrap-with-angular-2.html

Slides
http://csharp-video-tutorials.blogspot.com/2017/08/using-bootstrap-with-angular-2_14.html

Angular 2 Tutorial playlist

Angular 2 Text articles and slides
http://csharp-video-tutorials.blogspot.com/2017/06/angular-2-tutorial-for-beginners_12.html

All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd

All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists

In this video we will discuss
1. How to install and use Bootstrap with Angular
2. How to enable intellisense for bootstrap in Visual Studio

How to install and use Bootstrap with Angular : There are several ways to install Bootstrap. One way is by using Node.js command prompt.

Step 1 : Open node.js command prompt window.

Step 2 : In the command prompt navigate to the folder that contains your angular project and type the following command and press enter key. As Bootstrap has a dependency on jQuery, we are installing jQuery as well.
npm install bootstrap@3 jquery –save

This installs both Bootstrap and jQuery for use with our Angular project. The required Bootstrap and jQuery files are copied into the node_modules folder within the project directory.

Also, notice package.json file is also automatically updated with both the dependencies (Bootstrap and jQuery)

Step 3 : Finally in index.html file add the following script and link elements to reference the required CSS and JS files. As you can see, these files are being served from the node_modules folder.

[script src=”/node_modules/jquery/dist/jquery.min.js”][/script]
[link href=”/node_modules/bootstrap/dist/css/bootstrap.min.css” rel=”stylesheet” /]
[script src=”/node_modules/bootstrap/dist/js/bootstrap.min.js”][/script]

The problem at the moment is intellisense for Bootstrap CSS classes is not working in index.html, or any of the components html files

How to enable intellisense for bootstrap in Visual Studio : Use the following workaround to enable intellisense for bootstrap in Visual Studio.

Step 1 : In Visual Studio, click to select the Angular project and then click on “Show All Files” icon. You will then see “node_modules” folder.

Step 2 : Expand “node_modules” folder. Locate “bootstrap” folder. Right click on it and select “Include In Project” option from the context menu.

At this point you should get bootstrap intellisense in index.html and all angular component html files. If you still do not get bootstrap intellisense, please restart Visual Stduio and you will get intellisense.

As I said before, there are several ways to install bootstrap. One way is by using Node.js command prompt. The other way is by using Visual Stduio NuGet package manager. To install Bootstrap using NuGet package manager follow these steps.

Step 1 : In Visual Studio Solution Explorer, right click on the Angular project and select “Manage NuGet Packages” option from the context menu

Step 2 : In the “NuGet Package Manager” window
Click on the “Browse” link
In the textbox, type “Bootstrap” and press “enter” key
Click on the first item which says – Bootstrap
Click on the arrow pointing downwards to install

The required CSS and JS files are placed in Content and Script folders. Finally place the required CSS and JS files in index.html page to start using Bootstrap. If you install Bootstrap using NuGet you don’t have to do anything else to get bootstrap intellisense.

If you do not want to download bootstrap, you can use their CDN links. You can find the official Bootstrap CDN links at the following page.
http://getbootstrap.com/getting-started/

Besides these 3 ways, there are other ways of installing Bootstrap. Which way to use depends on your project needs.

Original source

21 thoughts on “Using Bootstrap with Angular 2

Leave a Reply