Uncaught (in promise): Error: StaticInjectorError(AppModule)[options]

后端 未结 8 1654
借酒劲吻你
借酒劲吻你 2020-12-01 14:08

I have a strange error. Usually (I did my googling), in this case of errors Angular specifies in square brackets which exactly module/service/provider/etc caused the problem

相关标签:
8条回答
  • 2020-12-01 14:12

    I was having the same problem using my class SharedModule.

    export class SharedModule {
        static forRoot(): ModuleWithProviders {
            return {
                ngModule: SharedModule,
                providers: [MyService]
             }
         }
    }
    

    Then I changed it putting directly in the app.modules this way

    @NgModule({declarations: [
    AppComponent,
    NaviComponent],imports: [BrowserModule,RouterModule.forRoot(ROUTES),providers: [MoviesService],bootstrap: [MyService] })
    

    Obs: I'm using "@angular/core": "^6.0.2".

    I hope its help you.

    0 讨论(0)
  • 2020-12-01 14:14

    HttpClientModule needs to be in the imports array, and remove it from providers. That section is for you to tell Angular which services the module has (written by you and not imported from a library).

    0 讨论(0)
  • 2020-12-01 14:16

    If we need to move from one component to another service then we have to define that service into app.module providers array.

    0 讨论(0)
  • 2020-12-01 14:16

    I had the same error and I solved it by importing HttpModule in app.module.ts

    import { HttpModule } from '@angular/http';
    

    and then in the imports[] array:

    HttpModule
    
    0 讨论(0)
  • 2020-12-01 14:17

    Faced the same error. In my case , what i did wrong was that i injected the service(named DataService in my case) inside the constructor within the Component but I simply forgot to import it within the component.

     constructor(private dataService:DataService ) {
        console.log("constructor called");
      }
    

    I missed the below import code.

    import { DataService } from '../../services/data.service';
    
    0 讨论(0)
  • 2020-12-01 14:26

    In my case, the error was in using angular2-notifications 0.9.8 instead of 0.9.7

    0 讨论(0)
提交回复
热议问题