ng.getComponent

global function

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:

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

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

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

© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v9.angular.io/api/core/global/ngGetComponent