title: Angular2: Unsubscribe from http observable in Service
body: <p>What is the best practice to unsubscribe within a Angular2 service from a http subscription?</p>
  
  <p>Currently I do this but I'm not sure if this will be the best way.</p>
  
  <pre><code>import { Injectable } from "@angular/core";
  import { Http } from "@angular/http";
  
  import { Subject } from "rxjs/Subject";
  import { ISubscription } from "rxjs/Subscription";
  
  @Injectable()
  export class SearchService {
      private _searchSource = new Subject&lt;any&gt;();
  
      public search$ = this._searchSource.asObservable();
  
      constructor(private _http: Http) {}
  
      public search(value: string) {
          let sub: ISubscription = this._http.get("/api/search?value=" + value)
              .map(response =&gt; &lt;any&gt;response.json())
              .do(data =&gt; this._searchSource.next(data))
              .finally(() =&gt; sub.unsubscribe()).subscribe();
      }
  
  }
  </code></pre>