【发布时间】:2016-12-07 19:49:52
【问题描述】:
我有 1 个组件和 1 个服务。
组件元素:
...
constructor(private requestService : RequestService)
{
}
ngOnInit()
{
this.a = this.requestService.send_request(urlWebAPI);
console.log(this.a);
}
...
服务:
constructor(private http: Http)
{
this.http = http;
this.headers = new Headers
({
'Content-Type': 'application/json'
});
}
send_request(additional_url: String)
{
return this.http.post(this.url + additional_url, {headers: this.headers})
.toPromise()
.then(response => response.json())
.catch(this.handleError);
}
private handleError(error: any)
{
console.error('An error occurred', error);
return Promise.reject(error.message || error);
}
【问题讨论】:
标签: json angular promise response