@mateusscheper wrote:
Hi!
I’m trying to print variables from my JSON but it’s returning a blank page.My products.php gets values from my MySQL db and return this:
{"products":[{"id":"1","name":"Arroz"},{"id":"2","name":"Feij?o"},{"id":"3","name":"Batata"},{"id":"4","name":"Leite"}]}
For a better view:
{ "products": [ { "id":"1", "name":"Arroz" }, { "id":"2", "name":"Feij?o" }, { "id":"3", "name":"Batata" }, { "id":"4", "name":"Leite" } ] }
My products.ts gets those values and my products.html print them:
products.ts:loader.present().then(() => { this.http.get('http://192.168.1.5/itens/products.php') .map(res => res.json()) .subscribe(data => { loader.dismiss() console.log(data); return data; }); });
I also tried another version (this one worked before, but I edited my products.php a lot because it was not working and now Ionic returns me a blank page):
loader.present().then(() => { this.http.get('http://192.168.1.5/itens/products.php') .map(res => res.json()) .subscribe(data => { this.products = data; this.products = Array.of(this.products); loader.dismiss() return this.products; }); });
products.html:
<ion-list> <ion-item *ngFor="let item of products"> {{ item.id }} {{ item.name }} </ion-item> </ion-list>
console.log:
Posts: 1
Participants: 1