ERROR Error: StaticInjectorError(AppModule)[UserformService -> HttpClient]:

前端 未结 9 1232
一整个雨季
一整个雨季 2021-02-03 17:55

While trying to add a PrimeNG table I broke my build here: https://github.com/BillyCharter87/Tech-O-Dex-UI/tree/BrokeIt

I recall updating my package.json fr

相关标签:
9条回答
  • 2021-02-03 18:01

    There are two reasons for this error

    1) In the array of import if you imported HttpModule twice

    2) If you haven't import:

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

    If you want then run:

    npm install @angular/http

    0 讨论(0)
  • 2021-02-03 18:04

    Import this in to app.module.ts

    import {HttpClientModule} from '@angular/common/http';
    

    and add this one in imports

    HttpClientModule
    
    0 讨论(0)
  • 2021-02-03 18:04

    There are two possible reasons 1. If you are using HttpClient in your service you need to import HttpClientModule in your module file and mention it in the imports array.

    import { HttpClientModule } from '@angular/common/http';
    
    1. If you are using normal Http in your services you need to import HttpModule in your module file and mention it in the imports array.

      import { HttpModule } from '@angular/http'

    By default, this is not available in the angular then you need to install @angular/http

    If you wish you can use both HttpClientModule and HttpModule in your project.

    0 讨论(0)
  • 2021-02-03 18:13

    In my case there was a need for:

    @Injectable({
        providedIn: 'root'  // <- ADD THIS
    })
    export class FooService { ...
    

    instead of just:

    @Injectable()
    export class FooService { ...
    
    0 讨论(0)
  • 2021-02-03 18:16

    provide all custom services means written by you in component decorator section Example : providers: [serviceName]

    note:if you are using service for exchanging data between components. declare providers: [serviceName] in module level

    0 讨论(0)
  • 2021-02-03 18:17

    Simply i have import in appmodule.ts

    import { HttpClientModule } from '@angular/common/http';
      imports: [
         BrowserModule,
         FormsModule,
         HttpClientModule  <<<this 
      ],
    

    My problem resolved

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