Ng-bootstrap not working in angular 4

I'm new to angular 4, I'm trying to configure bootstrap. I installed ng-bootstrap:

https://ng-bootstrap.imtqy.com/#/getting-started

I liked the page, but I do not see the boot page on my page. Here is my code:

SIC / application / app.module.ts

import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { FormsModule } from '@angular/forms'; import {NgbModule} from '@ng-bootstrap/ng-bootstrap'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, FormsModule, // add this NgbModule.forRoot() ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } 

SIC / application / app.component.html

 <div class="container"> <h1 class="text-primary">{{title}} </h1> <h2 class="text-primary">My Heroes</h2> <ul class="heroes"> <li *ngFor="let hero of heroes" [class.selected]="hero === selectedHero" (click)="onSelect(hero)"> <span class="badge">{{hero.id}}</span> {{hero.name}} </li> </ul> <div class="alert alert-success" role="alert"> <strong>Well done!</strong> You successfully read this important alert message. </div> <div *ngIf="selectedHero"> <h2>{{selectedHero.name}} details!</h2> <div><label>id: </label>{{selectedHero.id}}</div> <div> <label>name: </label> <input [(ngModel)]="selectedHero.name" placeholder="name"/> </div> 

I also tried some code in index.html, but it doesn’t work,

for this line, I expect to see some color:

 <h1 class="text-primary">{{title}} </h1> 

I cannot find the link to bootstrap when I check the html header. Any help please? Thanks

+7
angular twitter-bootstrap bootstrap-4 ng-bootstrap angular4-forms
source share
2 answers

On the mentioned page, ng-bootstrap mentions bootstrap CSS as a dependency. So it loads separately.

If you use the Angular CLI to create your application, follow this official guide to add it.

Update:

As mentioned in the comment, adding CSS to styles in .angular-cli.json (or any other changes in this file) will require a reboot of ng serve or ng build --watch if you already have one.

+10
source share

I do not see any ng-bootstrap component in your code! I think you are looking for bootstrap css, which is also a prerequisite for ng-bootstrap.

Add these lines in index.html between the <head></head> :

 <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <!-- Latest compiled and minified JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 
+1
source share

All Articles