Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
Angular 4 and Ionic 3 No provider for HTTP

I have a service which imports Http, and when I use it in my app it throws error. "No provider for Http! Error at g injectionError". I am lazyloading the app. Also the provider was generated through cli "ionic g provider ..."

complaint-service.ts

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

@Injectable()
export class ComplaintService {
    private complaints: {subject: string, description: string}[] = [];

    constructor(public http: Http) {
        this.http = http;
        this.complaints = null;
        console.log('Hello ComplaintService Provider');
    }

    addComplaints(complaint: {subject: string, description: string}) {
        this.complaints.push(complaint);
    }

    getComplaints() {
        return this.complaints.slice();
    }

}

complaint-form.ts

import { Component } from '@angular/core';
import {Validators, FormBuilder, FormGroup } from '@angular/forms';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {ComplaintService} from '../../providers/complaint-service';


@IonicPage()
@Component({
  selector: 'page-complaint-form',
  templateUrl: 'complaint-form.html',
  providers: [ComplaintService]
})
export class ComplaintForm {

}

Any suggestions?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You have to register the HttpModule to your module (/app.module.ts):

import { HttpModule} from '@angular/http';

@NgModule({
  imports: [
    HttpModule
  ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule {
}
about 4 years ago · Santiago Trujillo Report

0

Add HTTP to the providers list as well. (to AppModule)

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

And

  providers: [
    ...,
    HTTP 
  ]

Working with Angulat5+, Ionic 3+

about 4 years ago · Santiago Trujillo Report

0

HttpModule is deprecated in the latest version of ionic3 and Angular5. So, you have to use HttpClientModule instead of HttpModule. Other things will be same as @devqon's answer. After that, you can use HttpClient in your service or component file.

For more info, please refer to the original document of Angular.

https://angular.io/guide/http

import {HttpClientModule} from "@angular/common/http";

@NgModule({
  imports: [
    HttpClientModule
 ],
 declarations: [ AppComponent ],
 bootstrap:    [ AppComponent ]
})
export class AppModule {
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!