1

Setting up an accordion from here but the style is not importing correctly. I expected to see gray boxes like this:

GOAL:

enter image description here

However my code looks like this:

enter image description here


app.module imports (using forRoot() because of this):
NgbModule.forRoot()

HTML:

<ngb-accordion #acc="ngbAccordion" activeIds="ngb-panel-0">
  <ngb-panel title="Simple">
    <ng-template ngbPanelContent>
      Hi!
    </ng-template>
  </ngb-panel>
  <ngb-panel>
    <ng-template ngbPanelTitle>
      <span>&#9733; <b>Fancy</b> title &#9733;</span>
    </ng-template>
    <ng-template ngbPanelContent>
      lolzy
    </ng-template>
  </ngb-panel>
</ngb-accordion>
Rilcon42
  • 9,584
  • 18
  • 83
  • 167
  • What version of ng-bootstrap are you using? You no longer need to use `forRoot()` with the most recent versions. Older versions may have required you to import Bootstrap CSS. The question you mention is from 2016, the installation has drastically changed since then for `ng-bootstrap`. – Alexander Staroselsky Oct 24 '18 at 17:59

1 Answers1

2

The ng-bootstrap documentation indicates:

The only two dependencies are Angular and Bootstrap 4 CSS

You need to add a reference to Bootstrap 4.x.x CSS. This can either be done by adding a CDN <link> to your index.html. The following CDN is from the current Boostrap 4.x.x documentation:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

Or, if you are using @angular/cli, you can add Global Styles to your angular.json styles array property with the relative path from angular.json to the node_modules/bootstrap/dist/css/bootstrap.min.css:

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

You can also use import statements to the node_modules bootstrap.min.css in the style.css file.

@import '../node_modules/bootstrap/dist/css/bootstrap.min.css';

Hopefully that helps!

Alexander Staroselsky
  • 37,209
  • 15
  • 79
  • 91