Reputation: 587
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
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