I'm having trouble getting the data of my own api and reading them in the ionic app, basically I do not get an error, the get occurs on the server with code 200, but in the app I do not receive anything, thanks for the help
JSON response
[
{
"id": 1,
"username": "Emanuel",
"email": "emanuel",
"password": "123",
"created_at": "2018-01-17T12:04:43.000Z",
"updated_at": "2018-01-17T12:04:43.000Z"
}
]
rest.js
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable()
export class RestProvider {
constructor(public http: HttpClient) {
console.log('Hello RestProvider Provider');
}
apiUrl = 'http://localhost:3000';
getUsers(){
return new Promise(resolve => {
this.http.get(this.apiUrl+'/users').subscribe(data => {
console.log(data);
}, err => {
console.log(err);
});
});
}
}
home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { RestProvider } from '../../providers/rest/rest';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, public restProvider: RestProvider) {
this.getUsers();
}
users: any;
getUsers() {
this.restProvider.getUsers()
.then(data => {
this.users = data;
console.log(this.users);
});
}
}
home.html
<ion-header>
<ion-navbar>
<ion-title>
Probando Rest
</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-list inset>
<ion-item *ngFor="let user of users">
<h2>{{user.username}}</h2>
<p>{{user.email}}</p>
</ion-item>
</ion-list>
</ion-content>