{
"name": "ModalWindow",
"version": "1.0.0",
"repository": {
"type": "git",
"url": ""
},
"scripts": {
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development --open"
},
"license": "MIT",
"dependencies": {
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"core-js": "^2.5.5",
"rxjs": "6.3.0",
"rxjs-compat": "^6.3.3",
"sass": "^1.15.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@ng-bootstrap/ng-bootstrap": "^1.1.1",
"@types/node": "^10.0.4",
"angular2-template-loader": "^0.6.2",
"css-loader": "^0.28.11",
"html-webpack-plugin": "^3.2.0",
"less": "^3.0.4",
"less-loader": "^4.1.0",
"node-sass": "^4.10.0",
"raw-loader": "^0.5.1",
"sass-loader": "^7.1.0",
"style-loader": "^0.21.0",
"ts-loader": "^4.3.0",
"typescript": "^2.8.3",
"webpack": "4.8.1",
"webpack-cli": "^2.1.3",
"webpack-dev-server": "3.1.4"
}
}
This is my package.json,I don't understand what is wrong but tabset in ng-bootstrap is not working.
The main difference which noticed between the latest release 4.0.0 and the version which you are using in your package.json i.e ^1.1.1 is that in the latest release it's not necessary to import NgbModule as NgbModule.forRoot() . For example -
@NgModule({
imports: [BrowserModule, FormsModule, ReactiveFormsModule, HttpClientModule, NgbModule],
declarations: [....],
bootstrap: [...]
})
But if you import NgbModuleas above in the version 1.1.1 which you are using , you will get this below error
ERROR Error: StaticInjectorError(AppModule)[NgbTabset -> NgbTabsetConfig]: StaticInjectorError(Platform: core)[NgbTabset -> NgbTabsetConfig]: NullInjectorError: No provider for NgbTabsetConfig!
That is because in the lower version you need to use .forRoot() in your root module to make it available in all the other modules and components in your application.
So for the version 1.1.1 which you are using, you need to use the below code in your root module app.module.ts
@NgModule({
imports: [BrowserModule, FormsModule, ReactiveFormsModule, HttpClientModule, NgbModule.forRoot()],
declarations: [AppComponent, NgbdTabsetBasic],
bootstrap: [AppComponent]
})
Here is a complete example with Angular 5 and the ng-bootstrap version 1.1.1 which you are using -
package.json(same as what you are using)
{
"name": "ModalWindow",
"version": "1.0.0",
"repository": {
"type": "git",
"url": ""
},
"scripts": {
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development --open"
},
"license": "MIT",
"dependencies": {
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"@ng-bootstrap/ng-bootstrap": "1.1.1",
"core-js": "^2.5.5",
"rxjs": "6.3.0",
"rxjs-compat": "^6.3.3",
"sass": "^1.15.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@types/node": "^10.0.4",
"angular2-template-loader": "^0.6.2",
"css-loader": "^0.28.11",
"html-webpack-plugin": "^3.2.0",
"less": "^3.0.4",
"less-loader": "^4.1.0",
"node-sass": "^4.10.0",
"raw-loader": "^0.5.1",
"sass-loader": "^7.1.0",
"style-loader": "^0.21.0",
"ts-loader": "^4.3.0",
"typescript": "^2.8.3",
"webpack": "4.8.1",
"webpack-cli": "^2.1.3",
"webpack-dev-server": "3.1.4"
}
}
app.component.html
<div class="container-fluid">
<ngbd-tabset-basic></ngbd-tabset-basic>
</div>
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html'
})
export class AppComponent {
}
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { AppComponent } from './app.component';
import { NgbdTabsetBasic } from './tabset-basic';
@NgModule({
imports: [BrowserModule, FormsModule, ReactiveFormsModule, HttpClientModule, NgbModule.forRoot()],
declarations: [AppComponent, NgbdTabsetBasic],
bootstrap: [AppComponent]
})
export class AppModule {}
tabset-basic.html
<ngb-tabset>
<ngb-tab title="Simple">
<ng-template ngbTabContent>
<p>Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth
master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh
dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum
iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
</ng-template>
</ngb-tab>
<ngb-tab>
<ng-template ngbTabTitle><b>Fancy</b> title</ng-template>
<ng-template ngbTabContent>Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid.
<p>Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table
craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl
cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia
yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean
shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero
sint qui sapiente accusamus tattooed echo park.</p>
</ng-template>
</ngb-tab>
<ngb-tab title="Disabled" [disabled]="true">
<ng-template ngbTabContent>
<p>Sed commodo, leo at suscipit dictum, quam est porttitor sapien, eget sodales nibh elit id diam. Nulla facilisi. Donec egestas ligula vitae odio interdum aliquet. Duis lectus turpis, luctus eget tincidunt eu, congue et odio. Duis pharetra et nisl at faucibus. Quisque luctus pulvinar arcu, et molestie lectus ultrices et. Sed diam urna, egestas ut ipsum vel, volutpat volutpat neque. Praesent fringilla tortor arcu. Vivamus faucibus nisl enim, nec tristique ipsum euismod facilisis. Morbi ut bibendum est, eu tincidunt odio. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Mauris aliquet odio ac lorem aliquet ultricies in eget neque. Phasellus nec tortor vel tellus pulvinar feugiat.</p>
</ng-template>
</ngb-tab>
</ngb-tabset>
tabset-basic.ts
import {Component} from '@angular/core';
@Component({
selector: 'ngbd-tabset-basic',
templateUrl: './tabset-basic.html'
})
export class NgbdTabsetBasic { }
we need to add Bootstrap 4.0 css as dependency. The css can be added in 2 ways like below -
1. Add a <link> tag with the stylesheet in the index.html page
2. If you are using angular-cli then you can add it in the styles section of the .angular-cli.json file like
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css"
]
Here is a complete working demo https://stackblitz.com/edit/angular-wfkcak
update : After going through your stackblitz link I found that you have forgot to add the bootstrap 4 CSS file. I have added it in the index.html file.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
You can also add it to angular.json (for angular 6 ) or .angular-cli.json (for angular 5 ) which ever is applicable for you under styles array as I mentioned above.
Here is the updated stackblitz https://stackblitz.com/edit/angular-gmedf1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With