16

I am working on Angular application using bootstrap 4.

I need help related to scss adding in my angular application.

My question is:

  • Is the way of adding bootstrap 4 scss same in Angular 6 and Angular 7 or not?

i.e.

npm install bootstrap --save  

And, open angular.json file and add bootstrap file path to the styles section. Like:

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

Is the above way is same for both the version of angular.

5
  • Yes.But note in your script section jquery should come first then bootstrap js. Commented Feb 15, 2019 at 9:43
  • yes way is same as before Commented Feb 15, 2019 at 9:43
  • I use the same way. But you also need to include theter and jQuery in the scripts. Commented Feb 15, 2019 at 9:43
  • 1
    ng-bootstrap.github.io/#/home Commented Feb 15, 2019 at 9:45
  • Follow this blog post medium.com/@oyewusioyekunle/… Commented Jun 19, 2020 at 16:22

5 Answers 5

29

You need to do the following:

Add Bootstrap to package.json (which is done with npm install bootstrap --save)

Add Bootstrap to angular.json (jQuery is required too)

  "styles": [
     "styles.css".
     "../node_modules/bootstrap/dist/css/bootstrap.min.css"
  ],
  "scripts": [
     "../node_modules/jquery/dist/jquery.min.js",
     "../node_modules/popper.js/dist/umd/popper.min.js",
     "../node_modules/bootstrap/dist/js/bootstrap.min.js"
  ],

Reference Bootstrap in the Angular app (app.module.ts)

import bootstrap from "bootstrap";

Demo: https://codesandbox.io/s/kmm2q7zvko
Article: https://medium.com/wdstack/angular-7-bootstrap-4-starter-25573dff23f6

Sign up to request clarification or add additional context in comments.

3 Comments

use "styles.css", instead "styles.css".
import statement gives error node_modules/@types/bootstrap"' has no exported member 'bootstrap'.
@TheDoctor in your app.module.ts, try importing bootstrap like this: import * as bootstrap from 'bootstrap';
9

OPTION-1

execute

npm install bootstrap@4 jquery --save

The JavaScript parts of Bootstrap are dependent on jQuery. So you need the jQuery JavaScript library file too.

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

OPTION-2

ng-bootstrap It contains a set of native Angular directives based on Bootstrap’s markup and CSS. As a result, it's not dependent on jQuery or Bootstrap’s JavaScript

npm install --save @ng-bootstrap/ng-bootstrap

After Installation import it in your root module and register it in @NgModule imports` array

import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
@NgModule({
    declarations: [AppComponent, ...],
    imports: [NgbModule.forRoot(), ...],
    bootstrap: [AppComponent]
})

ng-bootstrap requires Bootstrap's 4 css to be added in your project. you need to Install it explicitly via:

npm install bootstrap@4  --save 

In your angular.json add the file paths to the styles array in under build target

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

Comments

7

Bootstrap not working properly in Angular 6 / 7 / 8

I tried most of the solution over web nothing work for me

Only below code work for me

No need to change in angular.json

Directly add below line into style.css file

@import "../node_modules/bootstrap/dist/css/bootstrap.css"

because in angular.json already we are providing reference of style.css

Comments

1

Remember, if ng serve is working, stop the server for the changes in the angular.json file to take effect.

Comments

0

You can put this path in angular.json file in style tag ex:-`enter code "styles": [ "./node_modules/bootstrap/dist/css/bootstrap.min.css "}

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.