title: Angular 2 - Two way communication between components
body: <p>I've this code...It's a sample tutorial application I'm trying to build that's reflect the daily basis needs of a developer.
  Actually, when the user types "fire" on the parent component, the child execute an event that's sends to the parent the word "booom" - It's a sample to demonstrate communication between a child component sending messages to a parent component using @Input and OnChanges.</p>
  
  <p>Now, I'm trying to do different: The parent should with some how tell to the child a message like "Target Locked" to the child when the user press the enter key (keyCode == 13). With this we will have a scenario of 2 way communication between components. </p>
  
  <p>What is the best approach ? </p>
  
  <p>child.component</p>
  
  <pre><code>import {Component, Input, OnChanges, EventEmitter,Output, Injectable} from 'angular2/core';
  @Injectable()
  @Component({
  selector: 'child-component',
  template: `&lt;p&gt;I'm the child component&lt;/p&gt;
  `
  })
  export class ChildComponent implements OnChanges { 
  @Input() txt: string;
  @Output() aim: EventEmitter&lt;any&gt; = new EventEmitter();
  ngOnChanges(changes: {[propName: string]: SimpleChange}) {
      var t = changes['txt'].currentValue;
      if(t == 'fire') {
          console.log('Fire !!!');
          this.aim.emit("booom !!!");
      }
  }
  }
  </code></pre>
  
  <p>parent.component</p>
  
  <pre><code>import {Component} from 'angular2/core';
  import {ChildComponent} from './child.component'
  @Component({
  selector: 'parent-component',
  directives : [ChildComponent]
  template: `&lt;p&gt;I'm the parent component&lt;/p&gt;
  &lt;input type="textbox" [(ngModel)]="theModel" (keydown)="arrow($event)"&gt;
  &lt;p&gt;feedback: {{feedback}}&lt;/p&gt;
  &lt;child-component txt="{{theModel}}" (aim)="feedback=$event"&gt;&lt;/child-component&gt;
  `
  })
  export class ParentComponent { 
  theModel;
  feedback;
  arrow (evt){
      if(evt.keyCode ==13) {
          //Need to cause an event on the child - a message like "Target Locked"
      };
  }
  }
  </code></pre>