angular2 - DatepickerConfig 没有服务提供商

标签 angular ng2-bootstrap ng2-datepicker

我正在实现 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]
})

组件.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]
})

By convention, the forRoot static method both provides and configures services at the same time. It takes a service configuration object and returns a ModuleWithProviders which is a simple object with two properties:

• ngModule - the CoreModule class

• providers - the configured providers

The root AppModule imports the CoreModule and adds the providers to the AppModule providers.

来源: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

关于angular2 - DatepickerConfig 没有服务提供商,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41587184/

相关文章:

javascript - Angular 选择选项时更改 src 属性

Angular 2+ - 动态设置基本 href

angular - ngFor 不工作

angular2 ng2-bootstrap 崩溃动画解决方法

css - 如何使用自定义 css 样式覆盖 ng2-bootstrap Accordion 默认样式

django - 找不到 ng2-bootstrap 下拉菜单

html - ng2-datepicker 选项不起作用

javascript - 链二选择 rxjs store in Angular Guard