0

I created angular app and install bootstrap using "npm install bootsrap" and add the path to angular.json file. but when i create a button and add bootstrap classes the output doesn't show applying bootstrap classes.

here what i get as an output

Can someone help me to solve this... thanks

user776686
  • 7,063
  • 12
  • 63
  • 105

4 Answers4

2

First things first you want to add bootstrap latest (5) as an npm package like so:

npm install bootstrap@next

In your angular.json add bootstrap stylesheet and javascript:

"styles": [
  "src/scss/styles.scss",
  "./node_modules/bootstrap/dist/css/bootstrap.min.css",
],

"scripts": [
  "./node_modules/bootstrap/dist/js/bootstrap.min.js"
]

Now add popperjs and add it to your scripts:

npm install @popperjs/core
"scripts": [
  "./node_modules/@popperjs/core/dist/umd/popper.min.js",
  "./node_modules/bootstrap/dist/js/bootstrap.min.js"
]

Now lets test and see if everything works accordingly Add a dropdown component to your app.component.html

<div class="dropdown">
  <button
    class="btn btn-secondary dropdown-toggle"
    type="button"
    id="dropdownMenuButton1"
    data-bs-toggle="dropdown"
    aria-expanded="false"
  >
    Dropdown button
  </button>
  <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
    <li><a class="dropdown-item" href="#">Action</a></li>
    <li><a class="dropdown-item" href="#">Another action</a></li>
    <li><a class="dropdown-item" href="#">Something else here</a></li>
  </ul>
</div>

You should be able to click and view the dropdown menu items

1

You can do this

npm i bootstrap --save

and add the bootstrap in angular.json

 "styles": [
       "node_modules/bootstrap/dist/css/bootstrap.css",
       "src/styles.scss"
 ],
 "scripts": [
      "node_modules/bootstrap/dist/js/bootstrap.js"
 ]



edhi.uchiha
  • 277
  • 2
  • 8
0

If you have angular version above 9+ you can use this

ng add @ng-bootstrap/ng-bootstrap

To get an idea you can refer this document: https://www.npmjs.com/package/@ng-bootstrap/ng-bootstrap

0

If you are using Sass, you need to do the following two steps:

  1. Install bootstrap using npm i bootstrap
  2. In angular.json file, add the following line to the styles array before any other entry: "./node_modules/bootstrap/scss/bootstrap.scss"

Your styles array should look like this ("build" -> "options" -> "styles"):

"styles": [
    "./node_modules/bootstrap/scss/bootstrap.scss",
    "src/styles.scss"
],
ilpianoforte
  • 456
  • 1
  • 2
  • 14