Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49229

Print variable.id from JSON

$
0
0

@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:
log

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49229

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>