ionic-native / http issues "NullInjectorError: No provider for HTTP!"

2

I'm starting in ionic 3.2 with angular, as per the linking documentation I installed on the project the @ionic-native/http module with the following commands via CMD:

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

Then in the script autenticar.ts (which is part of a page that I created autenticar.html ) I added import { HTTP } from '@ionic-native/http'; as:

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

@Component({
  selector: 'page-autenticar',
  templateUrl: 'autenticar.html'
})
export class AutenticarPage {

  @ViewChild('username') username;
  @ViewChild('password') password;

  constructor(public navCtrl: NavController, public http: HTTP) {
    console.log(http)
  }

...

While reloading the app I get the following error message:

Runtime Error
Uncaught (in promise): Error: StaticInjectorError(AppModule)
[AutenticarPage -> HTTP]: StaticInjectorError(Platform: core)[AutenticarPage -> HTTP]:
NullInjectorError: No provider for HTTP!
Error: StaticInjectorError(AppModule)[AutenticarPage -> HTTP]:
StaticInjectorError(Platform: core)[AutenticarPage -> HTTP]:
NullInjectorError: No provider for HTTP! at _NullInjector.get
(http://localhost:8100/build/vendor.js:1376:19) at resolveToken
(http://localhost:8100/build/vendor.js:1674:24) at tryResolveToken
(http://localhost:8100/build/vendor.js:1616:16) at StaticInjector.get
(http://localhost:8100/build/vendor.js:1484:20) at resolveToken
(http://localhost:8100/build/vendor.js:1674:24) at tryResolveToken
(http://localhost:8100/build/vendor.js:1616:16) at StaticInjector.get
(http://localhost:8100/build/vendor.js:1484:20) at resolveNgModuleDep
(http://localhost:8100/build/vendor.js:11228:25) at NgModuleRef_.get
(http://localhost:8100/build/vendor.js:12461:16) at resolveDep
(http://localhost:8100/build/vendor.js:12951:45)

So when reading this answer the author states that it is necessary to add to app.module.ts this import { HttpModule } from '@angular/http'; , it was like this :

import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { HttpModule } from '@angular/http';
import { MyApp } from './app.component';

....

  imports: [
    BrowserModule,
    HttpModule,
    IonicModule.forRoot(MyApp)
  ],

...

However even after installing and adding to the app.modules the error persists.

    
asked by anonymous 19.03.2018 / 02:33

1 answer

1

Take a look at item 2 of the link that you posted in the documentation. It says that you have to add the import to the providers of your module.

import { HTTP } from '@ionic-native/http';
...
imports: [
    BrowserModule,
    HttpModule,
    IonicModule.forRoot(MyApp)
  ],
providers: [
    HTTP
   ]
...
    
20.03.2018 / 13:21