我正在实现 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://github.com/valor-software/angular2-quickstart/blob/master/app/app.module.ts
关于angular2 - DatepickerConfig 没有服务提供商,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41587184/