2016-05-12 47 views
0

我想顯示一個JSON響應,但似乎無法顯示任何內容:離子2:無法顯示JSON響應眼簾

響應:

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; 
    } 

最後的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> 

任何人有一個想法,爲什麼我不能用* ngFor = 「響應#OBJ」 訪問?

回答

2

我認爲你的問題是在這裏:的

​​

代替:

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

根據您的響應有效載荷。

小記:您無需爲您的獲取請求設置Content-Type標題。