ionic 4 NullInjectorError: No provider for HTTP!
See original GitHub issueThe 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:
- Created 5 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Add “import { HTTP } from ‘@ionic-native/http/ngx’;” on your app.module.ts then add “HTTP” on the providers array
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.