Accepted answer

HttpClient needs for the module HttpClientModule instead of HttpModule to be imported and added in the imports of the module.

For more see Documentation

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

@NgModule({
    declarations: [
        ...
    ],
    imports: [
        ...
        HttpClientModule,
        ...
    ]
})
export class AppModuleShared { }
Accepted answer

step 1: import the HttpClientModule in app.module.ts:

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

step 2: inside the module imports add HttpClientModule:

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    HttpClientModule
  ],
  providers: [
    ....
  ],
  bootstrap: [AppComponent]
})

"NullInjectorError: No provider for HttpClient! problem in Ionic & Angular"

error =>

ERROR NullInjectorError: StaticInjectorError(AppModule)[TimeService -> HttpClient]: 
      StaticInjectorError(Platform: core)[TimeService -> HttpClient]:

Below solution is worked for me and I am using Angular version-9

=> Need to add => import {HttpClientModule} from '@angular/common/http'; in app.module.ts and also in the [import] array.



import this inside your app.module.ts.This will work

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

app.module.ts

import { HTTP } from '@ionic-native/http/ngx';


 providers: [
  ...,
HTTP 
  ],
mport { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import {HttpClientModule} from '@angular/common/http';
import { myService } from './myservice';


describe('myService', () => {

      beforeEach(() => TestBed.configureTestingModule({
        imports: [HttpClientTestingModule], 
        providers: [myService]
      }));

       it('should be created', () => {
        const service: myService = TestBed.get(myService);
        expect(service).toBeTruthy();
       });

       it('should have getData function', () => {
        const service: myService = TestBed.get(myService);
        expect(service.getData).toBeTruthy();
       });

    });
import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { myService } from './myservice';

describe('HeaderService', () => {
  beforeEach(() => TestBed.configureTestingModule({
    imports: [ HttpClientTestingModule ],
    providers: [myService]
  }));
});

adding HttpClientModule provider in imports section

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

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
  ]
})

This you need to add in src -> app -> app.module.ts file.

issue is more due to not registering the required services i.e HttpClientModule in the root module ie. NgModule.

You are missing HttpClientModule since you are receiving an error for HttpClient

You should import it in the app.module.ts file as follows,

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

and mention it in the NgModule Decorator like this -

@NgModule({
...
imports:[ HttpClientModule ]
...
})

app.module.ts -> import section, you need to add HttpClientModule. Below is the sample

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


    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        BrowserAnimationsModule,
        HttpClientModule,  // This is where you need to add
        FormsModule,
    ...