Emiry Mirella
Emiry Mirella

Reputation: 587

ionic 4 - http is found as undefined

I am trying to get some information from my Service using http on ionic.

I followed the tutorial found in the documentation: https://ionicframework.com/docs/native/http

I currently have a class where I can access my service and handle the data

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

@Injectable()
export class Repositorio {

    constructor(private http: HTTP) { }

    CarregaDados() {

        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.log(error.status);
                console.log(error.error); // error message as string
                console.log(error.headers);

            });

    }
}

however he always returns me the following error

core.js:9110 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'get' of undefined TypeError: Cannot read property 'get' of undefined

if i give a console log in http, i see that it is undefined, why it happens and how to treat it?

Upvotes: 0

Views: 939

Answers (1)

yazantahhan
yazantahhan

Reputation: 3110

Did you add the HTTP into providers in the app.module.ts?

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

@NgModule({
  ...
  providers: [HTTP]
  ...

Upvotes: 1

Related Questions