angular – 未处理的Promise拒绝:没有TranslateService的提供者

前端之家收集整理的这篇文章主要介绍了angular – 未处理的Promise拒绝:没有TranslateService的提供者前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
通过使用ng2-translation软件包,在angular2中使转换动态化
我得到的错误如下:未处理的承诺拒绝:没有TranslateService的提供商!

zone.js:388Unhandled Promise rejection: No provider for TranslateService! ; Zone: <root> ; Task: Promise.then ; Value: NoProviderError {_nativeError: Error: No provider for TranslateService!
at NoProviderError.BaseError [as constructor] (http://l…,keys: Array[1],injectors: Array[1]} Error: No provider for TranslateService!
at NoProviderError.BaseError [as constructor] (http://localhost:4200/main.bundle.js:7039:34)
at NoProviderError.AbstractProviderError [as constructor] (http://localhost:4200/main.bundle.js:43876:16)
at new NoProviderError (http://localhost:4200/main.bundle.js:43907:16)
at ReflectiveInjector_._throwOrNull (http://localhost:4200/main.bundle.js:62960:19)
at ReflectiveInjector_._getByKeyDefault (http://localhost:4200/main.bundle.js:62988:25)
at ReflectiveInjector_._getByKey (http://localhost:4200/main.bundle.js:62951:25)
at ReflectiveInjector_.get (http://localhost:4200/main.bundle.js:62760:21)
at AppModuleInjector.createInternal (AppModule.ngfactory.js:263:72)
at AppModuleInjector.NgModuleInjector.create (http://localhost:4200/main.bundle.js:44784:76)
at NgModuleFactory.create (http://localhost:4200/main.bundle.js:44769:18)

解决方法

我知道这个问题现在已经很老了,但是对于任何人来到这个页面寻找同样的问题,请仔细检查你是否在@NgModule providers数组中添加了服务.

在我的情况下,我想在一个模块中导入一个自定义服务’AuthGuard’,并不断收到错误’未处理的承诺拒绝:没有AuthGuard服务提供商’.我对这个问题的解决方法是 –

@NgModule({
    declarations: [
        TicketListComponent,TicketDetailComponent
    ],imports: [

        CommonModule,RouterModule.forChild(appRoutes)

    ],providers: [
        AuthGuard
    ]
})

猜你在找的Angularjs相关文章