4

I want to add bootstrap to angular. Specifically I'm having problems displaying icons from the library using code like

<i class="bi bi-star"></i>

I've added the line

              "./node_modules/bootstrap/dist/css/bootstrap.css"

in angular.json. I've also added

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

in styles.scss. Some funtions of bootstrap have been implemented on the app such as the formatting of buttons but it won't recognize bootstrap classes.

I hope I was clear. I'm just starting out and it's my first query on SO. Thanks in advance.

2

3 Answers 3

3

You need this:

npm install bootstrap

Solution 1: Write it to angular.json

"styles": ["node_modules/bootstrap/dist/css/bootstrap.min.css"],
"scripts": ["node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"]

Solution 2: import bootstrap to style.css

@import "~bootstrap/dist/css/bootstrap.css";
Sign up to request clarification or add additional context in comments.

5 Comments

I ran npm again and I added those lines of code. I restarted ng serve. Everything looks the same as before. It doesn't recognize bootstrap classes and I can't insert icons by changing the class of an element. Everything else looks like bootstrap.
I edited my answer. Please try the solution 2.
for icons there is seperate css you can look in node_modules/bootstrap
don't forget to restart angular application after doing changes in 'angular.json' file.
@mullern change the bootsrap spelling in ur answer
1

The easiest way to add Bootstrap 5 to your project is by pasting the href in the index.html on the header.

Comments

0

This is what solved it for me

Turns out the icons are now in a different module called bootstrap-icons and you have to import it separatelty.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.