簡體   English   中英

angular2-沒有DatepickerConfig的服務提供者

[英]angular2 - no service provider for DatepickerConfig

我正在實現ng2-bootstrap datepicker,但出現以下錯誤。 請幫我。

EXCEPTION: Uncaught (in promise): Error: Error in
         http://localhost:8888/app/components/report.component.html:3:0 caused by: No provider for DatepickerConfig! 

module.ts

 import { DatepickerModule } from 'ng2-bootstrap';

  @NgModule({
   imports: [DatepickerModule],
   declarations: [],
   providers: [],
   bootstrap: [AppComponent]
})

component.ts

@Component({
 module: module.id,
 selector:'my-date',
 template: `
  <h4>My Date Picker</h4>
  <datepicker></datepicker>`
})

 export class MyComponent {
 }

systemjs.config.js

System.config({ map: { 'ng2-bootstrap':
 'npm:ng2-bootstrap/bundles/ng2-bootstrap.umd.js'} })

您應該使用在示例存儲庫中以這種方式定義的forRoot()。

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

按照約定,forRoot靜態方法同時提供和配置服務。 它接受一個服務配置對象,並返回一個ModuleWithProviders,它是一個具有兩個屬性的簡單對象:

•ngModule-CoreModule類

•提供程序-已配置的提供程序

根AppModule導入CoreModule並將提供程序添加到AppModule提供程序。

來源: https: //angular.io/docs/ts/latest/guide/ngmodule.html#!#configure-core-services-with- coremodule-forroot

樣本存儲庫: https : //github.com/valor-software/angular2-quickstart/blob/master/app/app.module.ts

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM