服务.ts
get_update(id:any): Observable<any[]>{
let headers = new Headers({ 'Content-Type': 'application/json'});
let options = new RequestOptions({ headers: headers });
return this.http.get('http://localhost:8000/vendor/'+id,options)
.map(response => response.json())
.catch(error => Observable.throw(error.statusText));
}
component.ts
ngOnInit()
{ this.service.get_update(this.user).subscribe(data => console.log(data));
}
我想将数据存储到另一个变量中,并且我想转换为全局变量
最佳答案
我想您想记录响应? 你只需要
this.service.get_update(this.user).subscribe(update => console.log(update),
error => console.log(error));
关于angular - 如何从 Service 获取 component.ts 中的可见数据(可观察模式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49686591/