DRY code in Angular2 templates?
<p>I like the way you can easily bind properties, events etc. in angular2. You can put UI relevant code in your html and keep the component class pretty clean.</p>

<p>I have a snippet from a template i got, where i have a button to add the value of an input element, then clear the input field (to allow new input) and reset the focus in the element so you don't have to tab around a lot:</p>

<pre><code>&lt;div&gt;&lt;input #newPlayer type="text"&gt;
&lt;button type="button" 
(click)="addPlayer(newPlayer.value);newPlayer.value='';newPlayer.focus();"&gt;
ADD&lt;/button&gt;&lt;/div&gt;
</code></pre>

<p>My component code is something like this:</p>

<pre><code>public addPlayer(name: string) {
    if (!name.length) { return; };

    this.Players.push({ name: name});
}
</code></pre>

<p>This works great. The thing is, i figured that hitting the enter key in the input field should also behave like pressing the ADD button so my new html template looks like this:</p>

<pre><code>&lt;div&gt;&lt;input #newPlayer type="text" 
(keyup.enter)="addPlayer(newPlayer.value);newPlayer.value='';newPlayer.focus();"&gt;
&lt;button type="button" 
(click)="addPlayer(newPlayer.value);newPlayer.value='';newPlayer.focus();"&gt;
ADD&lt;/button&gt;&lt;/div&gt;
</code></pre>

<p>Having to type the same list of commands for the extra event seems overkill, so i figured - what is the best pattern here? I was contemplating something like this:</p>

<pre><code>&lt;div&gt;&lt;input #newPlayer type="text" 
(keyup.enter)="addPlayer(newPlayer)"&gt;
&lt;button type="button" 
(click)="addPlayer(newPlayer)"&gt;
ADD&lt;/button&gt;&lt;/div&gt;
</code></pre>

<p>Then change my component code to something like this:</p>

<pre><code>public addPlayer(element: any) { // ElementRef?
    if (!element.value?.length) { return; };

    this.Players.push({ name: element.value});
    element.value = '';
    element.focus();
}
</code></pre>

<p>I'm not sure if this would even work, perhaps i need a reference to <code>Renderer</code> as well as <code>ElementRef</code> and this would confirm my suspicion that I'm not supposed to do this.</p>

<p>What would the best practice be?</p>