我在stackoverflow上尝试了许多方法来解决这个错误,但是现在我只需要问一下,因为我已经花费了很多时间,却没有任何进展。
我有一个简单的服务:
constructor(private http: Http, private tokenResolver: TokenResolver) {}
public getEventHistory(): Observable<heatmapElement[]> {
this.tokenResolver.getToken(true).subscribe(token => {
var headers = new Headers();
headers.append('Authorization', 'Bearer ' + token);
headers.append('Content-Type', 'application/json');
this.result = this.http.get(this.restApi, new RequestOptions({headers: headers}))
.map((res: Response) => res.json());
});
return this.result as Observable<heatmapElement[]>;
}
我想使用以下代码获取数据:
public demoData: heatmapElement[] =[];
getEventHistory(): void {
this.eventHistoryService.getEventHistory()
.subscribe(data => this.demoData = data,);
}
这创建了一个错误,我似乎无法修复:
异常: 在http://localhost:5555/app/dashboard/dashboard.html:13:8中引起的错误:无法读取未定义的属性'subscribe' 类型错误: 无法读取未定义的属性'subscribe'
非常感谢您的帮助, 谢谢