I am implementing ng2-bootstrap datepicker, but getting the below error. 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
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'} })
You should use forRoot() as it is defined that way in the sample repository.
@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.
Source: 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With