JSON 응답을 표시하려고하는데 아무것도 표시되지 않는 것 같습니다.
응답:
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 of response"로 액세스 할 수없는 이유를 알고 있습니까?
나는 당신의 문제가 여기 있다고 생각합니다.
return this._http.get(this._url+'products?'+'consumer_key='+this._ck+'&consumer_secret='+this._cs, {
headers : headers
}).map(res => res.json().products); // <-----
대신에:
return this._http.get(this._url+'products?'+'consumer_key='+this._ck+'&consumer_secret='+this._cs, {
headers : headers
}).map(res => res.json().items);
응답 페이로드에 따라.
참고 : Content-Type
get 요청에 대해 헤더 를 설정할 필요가 없습니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다