2016-05-12 10 views
0

Ich versuche, eine JSON-Antwort angezeigt werden, aber kann nicht scheinen, etwas anzuzeigen:Ionic 2: Kann nicht angezeigt werden JSON-Antwort in Sicht

Antwort:

enter image description here

woo.service. ts:

getProducts() : Observable<any> { 
    let headers = new Headers(); 
    headers.append('Content-Type', 'application/x-www-form-urlencoded'); 
    return this._http.get(this._url+'products?'+'consumer_key='+this._ck+'&consumer_secret='+this._cs, { 
     headers : headers 
    }).map(res => res.json().items); 
} 

woo.ts:

ngOnInit() { 
     this._wooService.getProducts() 
     .subscribe(
      response => this.response = response, 
      error => console.log(error)); 
      this.isLoading = false; 
    } 

Und schließlich die woo.html:

<ion-card-header class="cardHead" text-center> 
    <h2 class="cardHeaderText">{{obj.products.title}}</h2> 

     <p>Prix: {{obj.price_html}}</p> 
</ion-card-header> 

<ion-card-content> 
    <img src="{{obj.images.src}}"> 
    <p class="cardBodyText">{{obj.description}}</p> 
    <p>Tags: {{obj.tags}}</p> 
    <p>Catégories: {{obj.categories}}</p> 
</ion-card-content> 

jemand eine Idee, warum ich nicht mit * ngFor = "# obj der Antwort" zugreifen kann?

Antwort

2

Ich denke, dass Sie ein Problem hier ist:

return this._http.get(this._url+'products?'+'consumer_key='+this._ck+'&consumer_secret='+this._cs, { 
    headers : headers 
}).map(res => res.json().products); // <----- 

statt:

return this._http.get(this._url+'products?'+'consumer_key='+this._ck+'&consumer_secret='+this._cs, { 
    headers : headers 
}).map(res => res.json().items); 

entsprechend Ihrer Antwort-Payload.

Ein kleiner Hinweis: Sie brauchen keinen Content-Type Header für Ihre Anfrage zu setzen.

Verwandte Themen