这是我的服务
countGroupByEtat(): Observable<number[]> {
return this.http.get(this.url + 'GroupByEtat', { headers: this.prepareHeaders() })
.map((res: Response) => {
let object: Array<any> = [];
let jsonResults: Array<any> = res.json();
jsonResults.forEach((jsonResult) => {
object.push(jsonResult);
});
return object;
})
}
和我的方法
getGroupByEtat(): number[] {
this.serviceDossier.countGroupByEtat()
.subscribe((data: number[]) => {
this.objects = data;
console.log("subsc"+ this.objects)
})
return this.objects;
}
当我想在this.objects
结束后获得subscribe
的值时,我收到一个空的数组,帮助!
答案 0 :(得分:2)
将其更改为:
getGroupByEtat(): number[] {
return this.serviceDossier.countGroupByEtat()
.subscribe((data: number[]) => {
this.objects = data;
console.log("subsc"+ this.objects)
return this.objects;
})
}