Source:  Twitter logo

While making translation dynamic in angular2, by using ng2-translation package I am getting error like : Unhandled Promise rejection: No provider for 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)

I know this question is quite old now, but for anyone who comes up to this page searching for the same issue, double check that you have added the service in @NgModule providers array.

In my case, I wanted to import a custom service 'AuthGuard' in a module, and kept getting the error 'Unhandled Promise rejection: No provider for AuthGuard service'. My Fix to the problem was-

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

        CommonModule,
        RouterModule.forChild(appRoutes)

    ],
    providers: [
        AuthGuard
    ]
})
6 users liked answer #0dislike answer #06
ashish-goel profile pic
ashish-goel

I had a similar problem and it turned out to be because I was importing 'CommonModule' but not importing 'BrowserModule' in my app.module.ts.

I removed 'CommonModule' and put 'BrowserModule' in the imports list and it fixed the problem....

1 users liked answer #1dislike answer #11
Irv Lennert profile pic
Irv Lennert

Add TranslateModule.forRoot() to your imports: section in your root NgModule.

0 users liked answer #2dislike answer #20
Amit profile pic
Amit

Copyright © 2022 QueryThreads

All content on Query Threads is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA 3.0).