I am just trying out this example to learn more about ionic 2. I just want to fetch and display the data in my ionic app.I am using mySQL database and PHP.When i run ionic serve, the data is fetched without any errors but i am just getting empty homepage. I have added my home.ts..,home.html and test.php file. Can anyone suggest me what am i doing wrong ? Thank you.
HOME.ts
import { Component } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
posts: any;
constructor(public http: Http ) {
this.http.get('http://192.000.00.000/test.php').map(res => res.json()).subscribe(data => {
this.posts = data.data.children;
},
err => {
console.log("Oops!");
});
}
}
home.html
<ion-header>
<ion-navbar>
<ion-title>Home Page</ion-title>
</ion-navbar>
</ion-header>
<ion-content class="home page" >
<ion-list>
<ion-item *ngFor="let post of posts">
<img [src]="post.data.url" />
</ion-item>
</ion-list>
</ion-content>
test.php
<?php
$output = array(
'success'=>'yes',
'data'=>555
);
echo json_encode($output);
?>

this.posts = data.data.children;.. yourdatadoes not havechildrenproperty.. so posts is undefined.