title: Angular http post to return data back through service to component
body: <p>I Want to return data (@@identity) from sql server through the service to the component </p>
  
  <p>The Web api is definitely being called and sending data back.</p>
  
  <p>However, since I am new to Angular 2/4  ( i was used to angular 1 )  i would normally just do  <code>return</code> on a service , and set a variable or object to the caller.</p>
  
  <p>Currently this is what I am doing </p>
  
  <p><strong>Component</strong></p>
  
  <pre><code>this.trackerFormService.addSession();  // CURRENT
  </code></pre>
  
  <p>but since the value is a single id,  like  5,   shouldn't i create something in typescript to retrieve it?</p>
  
  <pre><code>this.myId = this.trackerFormService.addSession();    // ???
  </code></pre>
  
  <p><strong>Then in the Service</strong> </p>
  
  <pre><code>private _url = 'http://localhost:60696/api/tracker';
  
  addSession() { 
      let headers = new Headers({ 'Content-Type': 'application/json' });
      let options = new RequestOptions({ headers: headers });
      this.http.post(this._url, JSON.stringify({}), options).catch(this.handleError).subscribe();
  
  }
  </code></pre>
  
  <p>Now for the above to pass the ID from the service (addSession() method back to component, shouldn't i do a <code>return</code> ?</p>
  
  <pre><code>return this.http.post(this._url, JSON.stringify({}), options).catch(this.handleError).subscribe();
  </code></pre>
  
  <p>but will that truly even work?  </p>
  
  <p>Web api (.net core )  looks like this </p>
  
  <pre><code>return Created($"api/sessiontrackers/{sessionTracker.Id}", sessionTracker);
  </code></pre>