MCPcopy
hub / github.com/angular/angular / getComponent

Function getComponent

packages/core/src/render3/util/discovery_utils.ts:57–71  ·  view source on GitHub ↗
(element: Element)

Source from the content-addressed store, hash-verified

55 * @publicApi
56 */
57export function getComponent<T>(element: Element): T | null {
58 ngDevMode && assertDomElement(element);
59 const context = getLContext(element);
60 if (context === null) return null;
61
62 if (context.component === undefined) {
63 const lView = context.lView;
64 if (lView === null) {
65 return null;
66 }
67 context.component = getComponentAtNodeIndex(context.nodeIndex, lView);
68 }
69
70 return context.component as unknown as T;
71}
72
73/**
74 * If inside an embedded view (e.g. `*ngIf` or `*ngFor`), retrieves the context of the embedded

Callers 5

componentInstanceMethod · 0.90
contextMethod · 0.90

Calls 3

getLContextFunction · 0.90
getComponentAtNodeIndexFunction · 0.90
assertDomElementFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…