title: How can I use ComponentRef to destroy my Component from within?
body: <p>I want to be able to destroy my component from within itself. (Not from parent since it's dynamically created in multiple areas). </p>
  
  <p>I've read from angular's api that they have a ComponentRef object. I've tried including it in the constructor but it says it needs an argument and I'm not sure what to pass to it.</p>
  
  <p>Link: <a href="https://angular.io/api/core/ComponentRef" rel="noreferrer">https://angular.io/api/core/ComponentRef</a></p>
  
  <p>How can use ComponentRef in my component to destroy it?</p>
  
  <pre><code>import { Component, ComponentRef, OnInit } '@angular/core';
  export class MyComponent implements OnInit {
      constructor(private ref: ComponentRef) {}
  
      ngOnInit() {
          this.ref.destroy()
      }
  }
  </code></pre>