• Overview
@angular/core/globals

getComponent

function

Retrieves the component instance associated with a given DOM element.

API

  
    function getComponent<T>(  element: Element): T | null;
  
  

getComponent

T | null

Retrieves the component instance associated with a given DOM element.

@paramelementElement

DOM element from which the component should be retrieved.

@returnsT | null

Usage Notes

Given the following DOM structure:

          
<app-root>  <div>    <child-comp></child-comp>  </div></app-root>

Calling getComponent on <child-comp> will return the instance of ChildComponent associated with this DOM element.

Calling the function on <app-root> will return the MyApp instance.

Jump to details