angular2 - 没有 DatepickerConfig 的服务提供商



我正在实现ng2-bootstrap日期选择器,但收到以下错误。请帮我解决这个问题。

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

模块.ts

 import { DatepickerModule } from 'ng2-bootstrap';
  @NgModule({
   imports: [DatepickerModule],
   declarations: [],
   providers: [],
   bootstrap: [AppComponent]
})

组件.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 - 核心模块类

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

根应用模块导入核心模块,并将提供程序添加到应用程序模块提供程序。

来源:https://angular.io/docs/ts/latest/guide/ngmodule.html#!#configure-core-services-with 核模块-根

示例存储库:https://github.com/valor-software/angular2-quickstart/blob/master/app/app.module.ts

最新更新