web-dev-qa-db-ja.com

Angular2 ng-bootstrap-プロバイダーエラーなし

私はng bootstrap UIを私のAngular 2プロジェクトに統合しようとしています。ここにある簡単な指示に従ってください: https:// ng -bootstrap.github.io/#/getting-started ngb bootstrapタグを使用すると、次のエラーが表示されます。

エラー:NgbAlertConfigのプロバイダーがありません!

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
import { StocksComponent } from './stocks/stocks.component';

import { HighlightDirective } from './highlight.directive';
import { StockService } from './stock.service';
import { DateFormatterPipe } from './date-formatter.pipe'

import { routing } from './app.routing';
import { DashboardComponent } from './dashboard/dashboard.component'

import { CurrencyService } from './currency.service';
import { BondsDirective } from './bonds.directive';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';


@NgModule({
  declarations: [
    AppComponent,
    StocksComponent,
    HighlightDirective,
    DateFormatterPipe,
    DashboardComponent,
    BondsDirective
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    routing,
    NgbModule
  ],
  providers: [StockService, CurrencyService],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

}

app.component.html

    <ngb-alert>
        Random Message
    </ngb-alert>

angular-cli.json

    {
      "project": {
        "version": "1.0.0-beta.17",
        "name": "my-prog-cli"
      },
      "apps": [
        {
          "root": "src",
          "outDir": "dist",
          "assets": "assets",
          "index": "index.html",
          "main": "main.ts",
          "test": "test.ts",
          "tsconfig": "tsconfig.json",
          "prefix": "app",
          "mobile": false,
          "styles": [
            "../node_modules/bootstrap/dist/css/bootstrap.css",
            "styles.css"
          ],
          "scripts": [
              "../node_modules/jquery/dist/jquery.js",
              "../node_modules/tether/dist/js/tether.js",
              "../node_modules/bootstrap/dist/js/bootstrap.js"
          ],
          "environments": {
            "source": "environments/environment.ts",
            "dev": "environments/environment.ts",
            "prod": "environments/environment.prod.ts"
          }
        }
      ],
      "addons": [],
      "packages": [],
      "e2e": {
        "protractor": {
          "config": "./protractor.conf.js"
        }
      },
      "test": {
        "karma": {
          "config": "./karma.conf.js"
        }
      },
      "defaults": {
        "styleExt": "css",
        "prefixInterfaces": false
      }
    }

CONSOLE ERROR

20
Paddy Urlich

このようにapp.module.tsにNgbModuleをインポートします

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

ngmodule-のimportsセクションに追加します

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

これが役立つかどうかを確認してください。

41
Sanket

別のコンポーネント、たとえばngbDropdownでこのエラーが発生する他の人は、親要素にngbDropdownが設定されていることを確認してください。

12
Darwayne