How to implement Bootstrap 4 in Angular CLI

Asked

Viewed 4,107 times

0

I’m having trouble using Bootstrap with the Angular CLI. I am using ng-bootstrap and I am following all the recommendations of the site, but without success, someone knows how to use?

installation via npm:

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

importing into the main module, with the . forRoot():

import {NgbModule} from '@ng-bootstrap/ng-bootstrap';

@NgModule({
   declarations: [AppComponent, ...],
   imports: [NgbModule.forRoot(), ...],
   bootstrap: [AppComponent]
})
export class AppModule {}

importing into the module with the component I am using:

import {NgbModule} from '@ng-bootstrap/ng-bootstrap';

@NgModule({
   declarations: [OtherComponent, ...],
   imports: [NgbModule, ...]
})
export class MeuModule {}
  • "but without success" ... Describe your problem! For someone else can make the test work.. So you are returning some error ?

  • No error returns, just no Bootstrap CSS works. No style.

3 answers

1


You need to add the Bootstrap in your project:

npm install bootstrap@4 --save

then edit the file .angular-cli.json:

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

Source: ng-bootstrap’s css Folder does not exist

0

Okay. The problem here is you forgot to add the css to your themese :D

in your main.scss (or equivalent) you only have to import the scss from the bootstrap:

// main.scss

// 3rd party libraries
@import "~bootstrap/scss/bootstrap";

and the bootstrap styles are in your style sheet

0

Use the command npm install bootstrap --save, and add the line:

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

as in the example below:

"build": { 
    "options": {
        "styles": [
            "../node_modules/bootstrap/dist/css/bootstrap.min.css",(adicionar essa inha no angular.json)
            "styles.css"
        ],
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.