title: Get Angular component class from DOM element
body: <p>I believe the answer to this is "no", but is there a method/service in Angular where I can pass in a component's root DOM node (e.g. <code>&lt;foo-component&gt;</code>) and receive the component instance (e.g. <code>FooComponent</code>)?</p>
  
  <p>I couldn't find an associated SO post on this.</p>
  
  <p>Example:</p>
  
  <pre><code>&lt;foo-component id="foo"&gt;&lt;/foo-component&gt;
  
  const fooElement: HTMLElement = document.getElementById('foo');
  const fooInstance: FooComponent = getInstanceFromElement(fooElement);
  </code></pre>
  
  <p>Is there a method in Angular like <code>getInstanceFromElement</code>?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I can't use <code>ViewChild</code>... I'm looking for a global service I can use. Suppose I am not invoking this method from the component class. I'm well acquainted with <code>ViewChild</code>/<code>ContentChild</code> and they are not what I'm looking for. Suppose I am in a globally injected service and am trying to do something like the following:</p>
  
  <pre><code>class MyService {
    constructor() {}
  
    getInstanceFromElement(element: HTMLElement): Component&lt;T&gt; {
      // Is there some special helper service I can use here?
    }
  }
  </code></pre>