自定义post类型wordpress工具集的Angular2 http get结果为空
我正在使用wordpress rest api和angular2构建简单的单页应用程序。我用工具集创建了一个自定义帖子类型。一切正常,我可以看到数据返回正常 在我的Angular应用程序中尝试请求数据时,响应主体为空 回应 _身体 : "[]" 标题 : 标题 好啊 : 真的 地位 : 200 状态文本 有人知道为什么会这样吗 http get的代码:自定义post类型wordpress工具集的Angular2 http get结果为空,wordpress,angular,Wordpress,Angular,我正在使用wordpress rest api和angular2构建简单的单页应用程序。我用工具集创建了一个自定义帖子类型。一切正常,我可以看到数据返回正常 在我的Angular应用程序中尝试请求数据时,响应主体为空 回应 _身体 : "[]" 标题 : 标题 好啊 : 真的 地位 : 200 状态文本 有人知道为什么会这样吗 http get的代码: getProductDownloads($id): Observable<any> { this.ProductsDo
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;
}
getProductDownloads($id):可观察{
this.ProductsDownloads=this.http.get(this.wpurl+'downloads/?filter[product]='+$id)
.map(res=>{
log('GET DOWNLOAD',res)
返回this.ProductsDownloads=this.extractData(res)
})
.接住(这个.把手错误);
返回此文件。产品下载;
}
要返回可观察对象本身:
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);
}
另外,您可以通过以下方式完成,并将|async
管道合并到模板中,而不是手动订阅和取消订阅
this.products = this.getProductDownloads(id);
// template:
{{ products | async }}
您希望返回可观察对象本身:
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);
}
另外,您可以通过以下方式完成,并将|async
管道合并到模板中,而不是手动订阅和取消订阅
this.products = this.getProductDownloads(id);
// template:
{{ products | async }}
您的api示例返回空结果。您的api示例返回空结果。