1

Why I can't load ng-bootstrap on my angular project ? does anyone experience the same thing ?

Thank you in advance

this is app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { AppRoutingModule } from './app-routing.module';

import { AppComponent } from './app.component';
import { NavbarComponent } from './navbar/navbar.component';
import { FooterComponent } from './footer/footer.component';


@NgModule({
  declarations: [
    AppComponent,
    NavbarComponent,
    FooterComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    NgbModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

1 Answers1

3

Judging from your code, you may have missed the NgbModule.forRoot() in the imports array in app.module.ts

In order to get ng-bootstrap to work in Angular, you have to do the following things:

  1. Install Bootstrap npm install --save bootstrap@4.0.0-beta.2
  2. Import Bootstrap into either

    • styles.css using @import "~bootstrap/dist/css/bootstrap.min.css";, or
    • .angular-cli.json via the styles property:

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

  3. Install ng-bootstrap npm install --save @ng-bootstrap/ng-bootstrap
  4. Import the ng-boostrap module into app.module.ts:

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

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

The install process is well documented in ng-boostrap's Getting Started Page

Stan
  • 476
  • 1
  • 5
  • 15