MCPcopy
hub / github.com/angular/angular / getOwningComponent

Function getOwningComponent

packages/core/src/render3/util/discovery_utils.ts:105–115  ·  view source on GitHub ↗
(elementOrDir: Element | {})

Source from the content-addressed store, hash-verified

103 * @publicApi
104 */
105export function getOwningComponent<T>(elementOrDir: Element | {}): T | null {
106 const context = getLContext(elementOrDir)!;
107 let lView = context ? context.lView : null;
108 if (lView === null) return null;
109
110 let parent: LView | null;
111 while (lView[TVIEW].type === TViewType.Embedded && (parent = getLViewParent(lView)!)) {
112 lView = parent;
113 }
114 return isRootView(lView) ? null : (lView[CONTEXT] as unknown as T);
115}
116
117/**
118 * Retrieves all root components associated with a DOM element, directive or component instance.

Callers 2

componentInstanceMethod · 0.90

Calls 3

getLContextFunction · 0.90
getLViewParentFunction · 0.90
isRootViewFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…