【发布时间】:2017-12-25 21:42:57
【问题描述】:
我已经导入了 'rxjs/add/operator/toPromise';
在我的 Ts 文件中,我有类似的内容:
onChange(categoryid) {
//console.log('testing')
this.productService.getProductsOncategory(categoryid).subscribe(data => {
if (data.success) {
console.log('Products obtained');
} else {
console.log('Not obtained!');
}
});
}
我得到错误:
“Promise”类型上不存在“订阅”属性。
getProductsOncategory(category_id) {
let catUrl = "API URL"
let headers = new Headers();
headers.append('Content-Type', 'application/json');
let catIdObj = JSON.stringify({ category_id: category_id })
return this.http.post(catUrl, catIdObj, { headers: headers })
.toPromise()
.then((response: Response) => response.json().data)
//.map((response: Response) => response.json())
//.do(data => console.log(JSON.stringify(data)))
.catch(this.handleError);
}
如果我必须使用 ' then(data => '...
,我该如何更改 sn-p【问题讨论】:
标签: javascript angular