【发布时间】:2017-12-22 23:22:22
【问题描述】:
getNews(newsType : any){
this.storage.get("USER_INFO").then(right=>{
this.storage.get("sessionkey").then(temp=>{
this.email = JSON.parse(right).email;
this.newkey = temp;
this.authentification =JSON.stringify("Basic " + btoa(this.email+":"+ this.newkey+":"+key));
const body = newsType;
let headers = new Headers({
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': this.authentification
});
let options = new RequestOptions({headers : headers});
return this.http.post('http://api/getNews',body,options)
.map((data:Response) => data.json());
}, err =>{console.log("error on sessionkey",err)})
}, err =>{console.log("error on user",err)})
}
this.httpService.getNews(JSON.stringify(this.category)).subscribe(data => {
this.news = data.News;
});
}, err => {
console.log("Error:", err)
});
我想在嵌套函数成功后调用Api。 但是当我在函数成功回调中执行它时,它给了我一个错误,即“void”类型上不存在属性“订阅”。
如何将 api 的值从服务返回到另一个 .ts 文件
【问题讨论】:
-
正如@Maximus 所说,您必须在嵌套函数
return this.storage.get("USER_INFO")内返回父(外部)级别的数据 -
嘿,如果有帮助,请考虑接受my answer
标签: javascript angular typescript ionic2 angular2-services