title: How to get last value from a Subject?
body: <p>I have two Angular2 components which need to share data via a service:</p>
  
  <pre class="lang-ts prettyprint-override"><code>@Injectable()
  export class SearchService {
    private searchResultSource = new Subject&lt;string&gt;()
    searchResult$ = this.searchResultSource.asObservable()
  
    setSearchResults(_searchResult: string): void {
      this.searchResultSource.next(_searchResult)
    }
  }
  </code></pre>
  
  <p>Suppose <code>ComponentA</code> is rendered and it emits an event via <code>SearchService.setSearchResults</code>. Then the user navigates to <code>ComponentB</code>, which also subscribes to <code>searchResult$</code>. However, <code>ComponentB</code> will never observe the event emitted by <code>ComponentA</code> because it was not subscribed to <code>searchResult$</code> at the time <code>ComponentA</code> emitted an event, as it did not exist.</p>
  
  <p>How can I create an <code>Observable</code> which emits the last event to every new subscriber?</p>