question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ionic 4 NullInjectorError: No provider for HTTP!

See original GitHub issue

The issue:

> NullInjectorError: No provider for HTTP!

steps to reproduce: 1-create a test project for ionic4:

ionic start ionic4-test sidemenu --type=angular

2-add the advanced http to the project: from link

ionic cordova plugin add cordova-plugin-advanced-http
npm install @ionic-native/http

3-add the android or ios platform to test the plugin:

ionic cordova platform add android

4- replace the <ion-content> in home.page.html with this:

<ion-button (click)="httpGet()">
      Test HTTP
    </ion-button>

5- replace home.page.ts to be like this:

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

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {


  constructor(
    private http: HTTP
  ) 
  {
    this.http.get('http://ionic.io', {}, {})
    .then(data => {

      console.log(data.status);
      console.log(data.data); // data received by server
      console.log(data.headers);

    })
    .catch(error => {

      console.error(error.status);
      console.error(error.error); // error message as string
      console.error(error.headers);

    });
  }
}

4-run the page to test the plugin usage:

ionic cordova run android 

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
pablo-fior-korbantechcommented, Feb 12, 2019

Add “import { HTTP } from ‘@ionic-native/http/ngx’;” on your app.module.ts then add “HTTP” on the providers array

1reaction
bcriglercommented, Apr 17, 2020

Well for me adding HTTP to the Providers array doesn’t even work. I will file an issue with ionic-native but capacitor is a broken mess, which is why they now released capacitor 2.0 and are working to create a plugin similar to this one.

Error: Invalid provider for the NgModule 'AppModule' - only instances of Provider and Type are allowed, got: [AuthGuardService, JwtHelperService, GoogleImageSearch, GifSearchService, LocalNotifications, ScreenOrientation, BackgroundMode, NativeAudio, Facebook, ?[object Object]?, ...]
    at syntaxError (compiler.js:2420)
    at compiler.js:21376
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getProvidersMetadata (compiler.js:21344)
    at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNgModuleMetadata (compiler.js:21062)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._loadModules (compiler.js:27117)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:27098)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler.compileModuleAsync (compiler.js:27058)
    at CompilerImpl.push../node_modules/@angular/platform-browser-dynamic/fesm5/platform-browser-dynamic.js.CompilerImpl.compileModuleAsync (platform-browser-dynamic.js:143)
    at compileNgModuleFactory__PRE_R3__ (core.js:27089)
capacitor.handleError @ capacitor-runtime.js:358
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ionic v4 : NullInjectorError: No provider for HTTP!
i am new to ionic and i want to use a service for retrieving data from the REST API but i get this...
Read more >
ionic-native/http emit error “NullInjectorError: No provider for ...
I try this answer, says I have to add the app.module.ts this import { HttpModule } from '@angular/http'; , like this: import {...
Read more >
How to fix No provider for HttpClient error in Angular
To fix NullInjectorError: No provider for HttpClient! follow the below steps 1. Open `app.module.ts` file 2. Import HttpClientModule from ...
Read more >
NG0201: No provider for {token} found! - Angular
You see this error when you try to inject a service but have not declared a corresponding provider. A provider is a mapping...
Read more >
No provider for HTTP! { HTTP Native} - Code Grepper
1. // add the provider in the app module ; 2. import { HTTP } from '@ionic-native/http/ngx'; ; 3. @NgModule({ ; 4. providers:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found