Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
Say hello to Angular's future home!Check out Angular.devHome
/

ng.getComponent

Retrieves the component instance associated with a given DOM element.

      
      ng.getComponent<T>(element: Element): T | null
    
Parameters
element Element

DOM element from which the component should be retrieved.

Returns

T | null: Component instance associated with the element or null if there is no component associated with it.

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.