The error message "NullInjectorError: No provider for HTTP!" is generated by the ionic-native/http module

Currently working with ionic 3.2 and angular. To install the HTTP module (https://ionicframework.com/docs/native/http/), I used the following commands:

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

In my script file autenticar.ts, I included the line

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

...

Upon reloading the app, I encountered 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)

I attempted to follow this answer, which suggested adding the line

import { HttpModule } from '@angular/http';
in the app.module.ts file, as shown below:

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, the error persisted despite these changes.

Answer №1

To include HTTP in the list of providers, you must follow these steps:

app.module.ts

...

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

...

@NgModule({
  ...

  providers: [
    ...
    HTTP
    ...
  ]
  ...
})
export class AppModule { }

Answer №2

To access the service, you must include HTTP within the providers

providers: [
    HTTP
]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Achieving a delayed refetch in React-Query following a POST请求

Two requests, POST and GET, need to work together. The POST request creates data, and once that data is created, the GET request fetches it to display somewhere. The component imports these hooks: const { mutate: postTrigger } = usePostTrigger(); cons ...

The reason behind encountering the "UNMET PEER DEPENDENCY" error within Angular 2

Is there a way to properly set up angular2-flash-messages in my angular-src directory instead of the root? I attempted to use npm install angular2-flash-messages, but encountered the following error: ├── UNMET PEER DEPENDENCY @angular/<a href="/c ...

Issue with Angular detection on the webpage: Protractor and headless chrome unable to locate Angular

Running end-to-end tests on my Angular2 app using Chrome works perfectly fine. However, when attempting to use headless Chrome with additional chromeOptions, it fails to locate the Angular app. I have tried setting directConnect to true and starting the se ...

How can I receive live notifications for a document as soon as it is created?

My Angular app is connected to Cloud Firestore, and I've created a function in a service to retrieve a user's rating from the 'ratings' collection. Each rating is stored in this collection with the document ID being a combination of the ...

Tips on filtering an array in a JSON response based on certain conditions in Angular 7

Looking to extract a specific array from a JSON response based on mismatched dataIDs and parentDataIDs using TypeScript in Angular 7. { "data":[ { "dataId":"Atlanta", "parentDataId":"America" }, { "dataId":"Newyork", ...

Triggering Backbutton actions in Ionic 3Just a heads-up

I need to capture the back button event before it triggers. Once the listener is activated, the back signal has already been sent. This is my approach so far: document.addEventListener("backbutton", () => { console.log("[WARN] Back button pres ...

Using React Native components from an external package leads to errors

I created a collection of React Native components by utilizing this template to seamlessly integrate Storybook. Additionally, I incorporated nativewind, which essentially serves as a React Native adaptation of Tailwind CSS. The structure of my components i ...

Execute a selector on child elements using cheerio

I am struggling to apply selectors to elements in cheerio (version 1.0.0-rc.3). Attempting to use find() results in an error. const xmlText = ` <table> <tr><td>Foo</td><td/></tr> <tr><td>1,2,3</td> ...

Having issues with *ngFor in Angular when trying to retrieve data from an API

I have been working on fetching data from an API and displaying it on the frontend, but I am facing an issue with *ngFor. Even though all variables seem to be set up correctly and I can see the data in the console.log, it is not showing up on the frontend. ...

Retrieving information from the Dog API using axios and storing the results in a fresh array

Currently, I am working on a NextJS app using Typescript. My issue lies in the functionality aspect of the application. I am utilizing the Dog API to retrieve all the breeds names and store them in a new array of arrays. Each sub-array contains the breed a ...

Encountering 'canvas.node' Issue While Setting up react-pdf-viewer with Next.js and TypeScript

I am having trouble integrating the "react-pdf-viewer" package into my Next.js project using TypeScript. I have downloaded the package via npm and followed the instructions in the documentation. However, when I try to compile my project, I encounter the fo ...

Incorporating Vaadin components into an Angular2-seed project

Hi there, I've been encountering an issue while trying to integrate Vaadin elements into my Angular2 seed project. The Vaadin team has recommended that I upgrade the systemjs.config.js file by specifying the path names for Vaadin elements like this: ...

Developing maintenance logic in Angular to control subsequent API requests

In our Angular 9 application, we have various components, some of which have parent-child relationships while others are independent. We begin by making an initial API call that returns a true or false flag value. Depending on this value, we decide whether ...

The specified '<<custom component name>>' argument does not match the 'Type<<custom component name>>' parameter

I'm currently facing an error that indicates a type parameters mismatch, but I can't pinpoint where in the process it's happening. Argument of type 'ModalUserInfoComponent' is not assignable to parameter of type 'Type<Mo ...

encountering a glitch while setting up Angular Material

Following the installation of angular-material using this command npm install --save @angular/material @angular/animations @angular/cdk Encountering an error when attempting to run 'ng serve'. This is perplexing because a similar installation ...

Typescript Angular2 filtering tutorial

In Angular 2 using TypeScript, the goal is to search for matching values from an array within an object array. The intention is to filter out any objects where the 'extraService' property contains any of the values from the 'array_values&apo ...

Unable to direct XHR requests even though the URL is functional in the browser

I am currently working on developing a REST API in TypeScript using NodeJS and Express. So far, the API is up and running on localhost. When I visit http://localhost:8080, everything functions as expected. Specifically, I have configured the route http:/ ...

How can I remove specific items from a PrimeNG PickList?

Currently, I'm working on a page where updates are made using PrimeNG PickList. The initial state of the target list is not empty, but when selected items are moved from source to target list, they are not removed from the source list as expected. Fr ...

Ways to retrieve a Class Level Variable within the onCellValueChanged function in agGrid

Exploring Angular with Typescript for the first time. I'm trying to access Class Level Variables within the onCellValueChanged event of agGrid, but encountering the following error: Cannot read property 'updateDict' of undefined Here&apo ...

Retrieving the data from a Material UI Slider control

I'm encountering an issue with retrieving the value property I assigned to a component. event.target.value is returning undefined. How can I successfully access the value of the component? My goal is for handlePlayersChange() to be able to handle dyn ...