In Angular 2, how do I submit an input type="text" value upon pressing enter? : <p>I'm building a search box in my Angular 2 app, trying to submit the value upon hitting 'Enter' (the form does not include a button). </p>

<p><strong>Template</strong></p>

<pre><code>&lt;input type="text" id="search" class="form-control search-input" name="search" placeholder="Search..." [(ngModel)]="query" (ngSubmit)="this.onSubmit(query)"&gt;
</code></pre>

<p>With a simple onSubmit function for testing purposes...</p>

<pre><code>export class HeaderComponent implements OnInit {
  constructor() {}

  onSubmit(value: string): void {
    alert('Submitted value: ' + value);
  }
}
</code></pre>

<p>ngSubmit doesn't seem to work in this case. So what is the 'Angular 2 way' to solve this? (Preferably without hacks like hidden buttons)</p>
