title: Angular 5 Adding a new instance of a component
body: <p>I am using angular 5 and I want to create new instances of a component on demand.</p>
  
  <p>This is the code I currently have:</p>
  
  <p>app.component.ts:</p>
  
  <pre><code>import { Component } from '@angular/core';
  import { MyComponent } from './mycomp/my.component';
  
  @Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss']
  })
  export class AppComponent {
    constructor() {}
    addCmp() {
      console.log('adding');
      // Add an instance of MyComponent code goes here ?
    }
  }
  </code></pre>
  
  <p>app.component.html</p>
  
  <pre><code>&lt;button (click)="addCmp()" &gt;Add New MyComponent below&lt;/button&gt;
  </code></pre>
  
  <p>MyComponent.html:</p>
  
  <pre><code>&lt;div&gt;I am MyComponent&lt;/div&gt;
  </code></pre>
  
  <p>How can I do this?</p>