简体   繁体   English

angular2-没有DatepickerConfig的服务提供者

[英]angular2 - no service provider for DatepickerConfig

I am implementing ng2-bootstrap datepicker, but getting the below error. 我正在实现ng2-bootstrap datepicker,但出现以下错误。 Please help me on this. 请帮我。

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 module.ts

 import { DatepickerModule } from 'ng2-bootstrap';

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

component.ts component.ts

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

 export class MyComponent {
 }

systemjs.config.js systemjs.config.js

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

You should use forRoot() as it is defined that way in the sample repository. 您应该使用在示例存储库中以这种方式定义的forRoot()。

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

By convention, the forRoot static method both provides and configures services at the same time. 按照约定,forRoot静态方法同时提供和配置服务。 It takes a service configuration object and returns a ModuleWithProviders which is a simple object with two properties: 它接受一个服务配置对象,并返回一个ModuleWithProviders,它是一个具有两个属性的简单对象:

• ngModule - the CoreModule class •ngModule-CoreModule类

• providers - the configured providers •提供程序-已配置的提供程序

The root AppModule imports the CoreModule and adds the providers to the AppModule providers. 根AppModule导入CoreModule并将提供程序添加到AppModule提供程序。

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

Sample repository: https://github.com/valor-software/angular2-quickstart/blob/master/app/app.module.ts 样本存储库: 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