title: place cursor at end of value of input field on focus | angular 2
body: <p>I have a dynamic component being created and on <code>ngAfterViewInit</code> I've done the following code:</p>
  
  <pre><code>setTimeout(() =&gt; {
    this.input.nativeElement.focus();
  }, 0);
  </code></pre>
  
  <p>This works: it sets the focus on the input correctly, but the cursor is placed at the beginning of the value. I would like to place the cursor at the end of the value.</p>
  
  <p>I've tried this:</p>
  
  <pre><code>setTimeout(() =&gt; {
    this.input.nativeElement.focus();
    let start = this.input.nativeElement.selectionStart;
    let end = this.input.nativeElement.selectionEnd;
    this.input.nativeElement.setSelectionRange(start,end);
  }, 0);
  </code></pre>
  
  <p>I've also tried clearing the value and resetting it but cant get it to work.</p>
  
  <p>Heres the html and how I'm accessing it:</p>
  
  <pre><code>&lt;input class="nav-editor__input" #input type="text"&gt;
  
  @ViewChild('input') input: ElementRef;
  </code></pre>
  
  <p>Any ideas?</p>