title: Angular 7 - Add drag and drop behaviour to dynamically created components
body: <p>This is in continuation of the previous question I asked on SO:
  <a href="https://stackoverflow.com/questions/56072516/add-directives-to-component-selector-when-it-is-declared-angular-7">Add directives to component selector when it is declared - Angular 7</a></p>
  
  <p>I am dynamically creating components on a button click. The components are displayed one below another in a list like manner. I want to introduce drag-drop behaviour so that the user can rearrange the components after creating them.</p>
  
  <p>In the previous question, I tried using Angular-Material, but realised it might not be possible to use it for components, due to the issue of adding "cdkDrag" directive to the component's selector tag, and the fact that the cdkDropList and cdkDrag might need to be in the same template.</p>
  
  <p>I have a div as such in the template:</p>
  
  <pre><code>&lt;div cdkDropList style="margin: 20px" (cdkDropListDropped)="drop($event)"&gt;
      &lt;div #container&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And, I am creating custom components as follows:</p>
  
  <pre><code>@ViewChild('container', {read: ViewContainerRef})
    container: ViewContainerRef;
  
  const childComponent = this.componentFactoryResolver.resolveComponentFactory(CustomComponent);
  const component = this.container.createComponent(childComponent);
  </code></pre>
  
  <p>This works fine. Is it possible at all to create draggable dynamically created components?</p>
  
  <p>Thank you.</p>