title: Add Text to an Existing Input Field on Button Click
body: <p>I am creating a site where admins on the site will routinely post articles (much like a blog). I as an admin can write a basic HTML document easily, but the other admins are not at all familiar with HTML.</p>
  
  <p>I have a form that they will use to publish their articles with author, title, and content fields. I am currently taking the 'content' field and displaying it as HTML after the form is submitted. To help the other users I have added buttons that say "header", "paragraph", "image", and "line break". When these buttons are clicked I would like to add html tags to the existing field (usually already filled with article text). </p>
  
  <p>The idea is this:</p>
  
  <p>I click the paragraph button and my field shows this: 
      "<code>&lt;p&gt;type here&lt;/p&gt;</code>".
  I then type the paragraph and go to a new line. I decide to add a sub heading after it and click the heading button: </p>
  
  <pre><code>&lt;p&gt;I replaced the text&lt;/p&gt;
  &lt;h3&gt;type sub-heading here&lt;/h3&gt;
  </code></pre>
  
  <p>I don't want the button to create a new input or add to the form in any way. I also don't want it to replace or reset the text that is there, but simply add text where the cursor is located. I've found plenty of methods to add form fields, replace them, hide them, etc, but can't dig up any posts about editing existing text with a button.</p>
  
  <p>Anyone know how I can do this? I am using angular 2 as a framework, so any solution that fits with it (javascript, typescript, angular 2 data binding, etc) will work.</p>
  
  <p>Here is my HTML:</p>
  
  <pre><code>&lt;div class="edit-article"&gt;
    &lt;h2 *ngIf="isEdit"&gt;Edit an Article&lt;/h2&gt;
    &lt;h2 *ngIf="!isEdit"&gt;Add an Article&lt;/h2&gt;
    &lt;div class="input-group"&gt;
      &lt;label for="title"&gt;Title&lt;/label&gt;
      &lt;input mdInput id="title" type="text" [(ngModel)]="title"&gt;
  
      &lt;label for="author"&gt;Author&lt;/label&gt;
      &lt;input mdInput id="author" type="text" [(ngModel)]="author"&gt;
  
      &lt;label for="article-content"&gt;Content&lt;/label&gt;
      &lt;input mdInput id="article-content" type="textarea" class="multi-line-input" [(ngModel)]="content"&gt;
    &lt;/div&gt;
    &lt;div class="button-group left"&gt;
      &lt;button class="button secondary" (click)='onAddHeader()'&gt;Header&lt;/button&gt;
      &lt;button class="button secondary" (click)='onAddParagraph()'&gt;Paragraph&lt;/button&gt;
      &lt;button class="button secondary" (click)='onAddImage()'&gt;Image&lt;/button&gt;
    &lt;/div&gt;
    &lt;div class="button-group right"&gt;
      &lt;button class="button primary" (click)="onSaveArticle()"&gt;Save&lt;/button&gt;
  </code></pre>
  
  <p>TS file:</p>
  
  <pre><code>export class ArticleEditComponent {
    isEdit = false;
  
    public title: string;
    public author: string;
    public content: string;
  
    constructor(
      public dialogRef: MdDialogRef&lt;any&gt;, @Inject(MD_DIALOG_DATA) private dialogData: any,
      public afAuth: AngularFireAuth, public afDB: AngularFireDatabase,
      public articleService: ArticleService) {
    }
  
    onSaveArticle() {
      this.articleService.createArticle(new Article(
      this.title, this.author, this.content));
    }
  
  onAddHeader(){
      document.getElementById("article-content").innerText += '&lt;h3&gt;&lt;/h3&gt;';
      console.log('running header function');
    }
  
    onAddImage(){
      document.getElementById("article-content").innerText += 'add image tag';
      console.log('running header function');
    }
  
    onAddParagraph(){
      document.getElementById("article-content").innerText += '&lt;p&gt;&lt;/p&gt;';
      console.log('running header function');
    }
  </code></pre>