title: Assign value returned by Http subscribe method in Angular2
body: <p>I have an issue when I call my webservice in Angular2. My variable <code>this.arc</code> is always empty because the function <code>get()</code> is asynchronous and it return directly the variable before webservice's response.</p>
  
  <p>I don't know how to handle this.
  I saw some informations about <code>defer</code> but i think is not the best way.</p>
  
  <p>Thanks !</p>
  
  <pre><code>getArcs (lat,lng) {
      var url = "http://localhost:8081/api/v1/arcs?lat="+lat+"&amp;lng="+lng;
      this.arcs = [];
  
      /*var options = new RequestOptions({
          headers: new Headers({
              'Content-Type': 'application/json;charset=UTF-8'
          })
      });*/
  
      this.http.get(url)
      .subscribe(
              (data: any) =&gt; {
                  JSON.parse(data._body).forEach(arc =&gt; {
                      //console.log(new Arc(arc));
                      this.arcs.push(new Arc(arc)); //add arcs
                  });
                  console.log("send");
  
              },
              error =&gt; {
                  console.log("error during http request");
              }
          );
      return this.arcs;
  }
  </code></pre>
  
  <p>---- EDIT----</p>
  
  <p>I think the problem is at the call of the function : </p>
  
  <pre><code>public getData (lat,lng) {
      var closedArc = this.arcService.getArcs(lat,lng);
  
      console.log(closedArc);
  
      //this.showArc(closedArc);
  }
  </code></pre>