gpt4 book ai didi

angular2 - DatepickerConfig 没有服务提供商

转载 作者:行者123 更新时间:2023-12-02 12:14:44 24 4
gpt4 key购买 nike

我正在实现 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com