title: Emit search input value to child components in Angular 2
body: <p>In an Angular 2 app, I have an HTML search input whose value I want to send to 3 child components, only if the user stops typing for 300ms and he typed something different than what   input contained. I've read some articles on the Internet and all of them mention the use of <code>Subject</code>, <code>debounceTime</code> and <code>distinctUntilChanged</code> operators. Following one of the tutorials, I ended up with the following code:</p>
  
  <p><strong>PARENT COMPONENT:</strong></p>
  
  <pre><code>// Subject to emit an observable
  public searchUpdated: Subject &lt;string&gt; = new Subject&lt;string&gt;();
  
  @Output() searchChangeEmitter: EventEmitter &lt;any&gt; = new EventEmitter &lt;any&gt;();
  
  constructor() {
    [.......]
    this.searchChangeEmitter = &lt;any&gt;this.searchUpdated.asObservable()
      .debounceTime(300)
      .distinctUntilChanged(); // accept only relevant chars
  }
  
  onSearchType(value : string) {
    this.searchUpdated.next(value); // Emit the changed value to the subscribers
  }
  </code></pre>
  
  <p><strong>PARENT TEMPLATE:</strong></p>
  
  <pre><code>&lt;input class="input-group-field" type="search" id="inputSearch" name="inputSearch" (keyup)="onSearchType($event.target.value)"&gt;
  </code></pre>
  
  <p>I want to pass the emitted value to the child components but I'm feeling a little lost. I've tried this but it didn't work:</p>
  
  <p><strong>PARENT TEMPLATE</strong></p>
  
  <pre><code>&lt;app-object-tree [searchFilter]="searchChangeEmitter"&gt;&lt;/app-object-tree&gt;
  </code></pre>
  
  <p>(And, in the child component 'app-object-tree', create the @Input 'searchFilter' and subscribe to it to try to get the value.)</p>
  
  <p>It makes more sense to me to create a service, provide it in the parent component and subscribe to it on the child components, but I don't know how to call the service 'setter' function after applying the 'debounceTime' and 'distinctUntilChanged' operations.</p>
  
  <p>Thanks a lot, and sorry if I didn't explain myself correctly, I'm still trying to tie all the Subject/Observable concepts in my mind.</p>