Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic-native/http emit error “NullInjectorError: No provider for HTTP!”

I'm using ionic 3.2 and angular, for install HTTP (https://ionicframework.com/docs/native/http/) I use this commands:

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

In script autenticar.ts I added the import { HTTP } from '@ionic-native/http'; like this:

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)
  }

...

After reload app I get this error:

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)

I try this answer, says I have to add the app.module.ts this import { HttpModule } from '@angular/http';, 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)
  ],

...

But still the same error.

like image 840
Guilherme Nascimento Avatar asked Dec 11 '22 07:12

Guilherme Nascimento


1 Answers

You need to add HTTP in providers

app.module.ts

...

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

...

@NgModule({
  ...

  providers: [
    ...
    HTTP
    ...
  ]
  ...
})
export class AppModule { }
like image 108
Javascript Hupp Technologies Avatar answered May 23 '23 23:05

Javascript Hupp Technologies