title: Making Subscribe to wait in Angular 4 for Subject
body: <p>I have a text field in my HTML which calls back-end service in real time based on text entered. If a user enters something like 'abc', my service returns an object array which has this 'abc' name.</p>
  
  <p>I am using Observable and Subject for this and I am returning processed service in my component. Please see the code.</p>
  
  <p><strong>HTML Code</strong></p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;input size="30" type="text" (keyup)="searchTerm$.next($event.target.value)"&gt;
  </code></pre>
  
  <p><strong>Component Code</strong></p>
  
  <pre><code>import { Subject } from 'rxjs/Subject';
  
  searchString$ = new Subject&lt;string&gt;();
  
  constructor() {
  
      this.searchString$.debounceTime(500)
      .distinctUntilChanged()
        .map(searchText =&gt; {
          return this.backEndService.fetchSearchStringData(searchText);
        })
        .subscribe(result =&gt; {
          console.log('result');
          console.log(JSON.stringify(result));
  
        });
  }
  </code></pre>
  
  <p>When I I type 'abc' then it calls this <strong>fetchSearchStringData</strong> method. The service call is nothing but simple restService.post call and then setting the object is observable. Using that data to filter something and returning the finalized array.</p>
  
  <p>But my component .subscribe us getting called first and only one time and it shows undefined value. (Where I am consoled.logging 'result').</p>
  
  <p>How do I make sure I get the data once it gets a return from service in my subscribe of the component?</p>
  
  <p>Thanks in advance.</p>