0

this is my service

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

and my method

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

      })
    return this.objects;
  }

When I want to obtain the value of this.objects after the closing of subscribe I receive an array that is empty, help !

Christopher
  • 1,712
  • 2
  • 21
  • 50
M.angular2
  • 9
  • 1
  • 4

1 Answers1

2

Change it to :

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

        return this.objects;
      })

  }
Radouane ROUFID
  • 10,595
  • 9
  • 42
  • 80