2017-01-06 8 views
1

私は単純な1ページのアプリケーションを構築するためにwordpress rest apiとangular2を使用しています。私は、ツールセットでカスタムポストタイプを作成しました。すべて正常に動作しており、データが正常に戻ってくるのがわかります。Angular2 httpはカスタムポストタイプ用の空の結果を得ます。Wordpressツールセット

http://tncorp.biffapps.com/wp-json/wp/v2/downloads/?filter[product]=Pico

Screenshot

レスポンスボディが空である、私の角のアプリケーションでデータを要求しようとします。

応答 _body : "[]" ヘッダ : ヘッダ OK : 真 状況 : STATUSTEXT

これはhappingている理由誰でも知っていますか? HTTP GETのため

コード:

getProductDownloads($id): Observable<any> { 

    this.ProductsDownloads = this.http.get(this.wpurl + 'downloads/?filter[product]='+$id) 
     .map(res => { 
      console.log('GET DOWNLOAD',res) 
      return this.ProductsDownloads = this.extractData(res) 
     }) 
     .catch(this.handleError); 

    return this.ProductsDownloads; 
} 
+1

apiの例は空の結果を返します。 – Erevald

答えて

0

は、あなたが観測自体を返すようにしたい:あなたはそれを呼び出しているとき

getProductDownloads($id): Observable<any> { 
    return this.http.get(this.wpurl + 'downloads/?filter[product]='+$id) 
    .map(res => { 
     console.log('GET DOWNLOAD',res) 
     return this.ProductsDownloads = this.extractData(res) 
    }) 
    .catch(this.handleError); 
} 

次に、あなたが観察可能にを購読

// I'm using "this" here, but if you have it in a -service- you'd put that there 
this.getProductDownloads(id).subscribe(result => { 
    this.products = result; 
}); 

また、手動で退会&をサブスクライブするのではなく、それを次のように行うと、あなたのテンプレートに| asyncパイプを組み込むことができます。

this.products = this.getProductDownloads(id); 

// template: 
{{ products | async }} 
関連する問題