Ionic v4 : NullInjectorError: No provider for HTTP!

hi every body,

i am new to ionic and i want to use a service for retrieving data from the REST API but i get this error !

i am using ionic v4

No provider for http. I think your error is that u didnt import it.

import { HttpClient } from ‘@angular/common/http’;

And in the constructor:

constructor(
public http: HttpClient
)

1 Like

thanks for help
but this is my code :

import { Injectable } from '@angular/core';
import { HTTP } from '@ionic-native/http/ngx';

@Injectable({
  providedIn: 'root'
})
export class LoginService {

  items:any;

  constructor(private http: HTTP) {
  }

  // service that test if the user exist or not
  authentification(user:string,password:string){

    this.http.get('http://domain.com/myapi/user', {}, {})
        .then(data => {
          //console.log(data.data); // data received by server
          this.items = data.data;
        })
        .catch(error => {
          console.log(error.error); // error message as string

        });
   
     return this.items;
  }


}

app.module.ts

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


 providers: [
  ...,
HTTP 
  ],
2 Likes