2017-07-20 132 views
0

這是我的服務角2個返回數據從訂閱

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; 
    } 

當我想要的subscribe截止後,得到的this.objects I的值接收一個數組,它是空,幫忙!

+0

檢查'在方法返回this.object'和'在服務 – k11k2

+0

返回object' @服務k11k2對象是全但this.object的方法=>在認購已滿,但沒有訂閱是空的 –

回答

2

將其更改爲:

getGroupByEtat(): number[] { 
    return this.serviceDossier.countGroupByEtat() 
     .subscribe((data: number[]) => { 
     this.objects = data; 
     console.log("subsc"+ this.objects) 

     return this.objects; 
     }) 

    } 
+0

j'aidéjàpenséàfaireça.. mais cettefaçonne me permet pas de returner un tableau –

+0

Quel est lerésultatou l'erreur obtenu? –

+0

jereçoisune tableau vide –