Spec-Zone.ru › Angular

getComponent

Retrieves the component instance associated with a given DOM element.

API

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

DOM element from which the component should be retrieved.

@returnsT | 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.

Super-powered by Google ©2010–2025.
Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0.
https://angular.dev/api/core/globals/getComponent

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API