MCPcopy
hub / github.com/angular/angular / findViaComponent

Function findViaComponent

packages/core/src/render3/context_discovery.ts:266–286  ·  view source on GitHub ↗

* Locates the component within the given LView and returns the matching index

(lView: LView, componentInstance: {})

Source from the content-addressed store, hash-verified

264 * Locates the component within the given LView and returns the matching index
265 */
266function findViaComponent(lView: LView, componentInstance: {}): number {
267 const componentIndices = lView[TVIEW].components;
268 if (componentIndices) {
269 for (let i = 0; i < componentIndices.length; i++) {
270 const elementComponentIndex = componentIndices[i];
271 const componentView = getComponentLViewByIndex(elementComponentIndex, lView);
272 if (componentView[CONTEXT] === componentInstance) {
273 return elementComponentIndex;
274 }
275 }
276 } else {
277 const rootComponentView = getComponentLViewByIndex(HEADER_OFFSET, lView);
278 const rootComponent = rootComponentView[CONTEXT];
279 if (rootComponent === componentInstance) {
280 // we are dealing with the root element here therefore we know that the
281 // element is the very first element after the HEADER data in the lView
282 return HEADER_OFFSET;
283 }
284 }
285 return -1;
286}
287
288/**
289 * Locates the directive within the given LView and returns the matching index

Callers 2

getLContextFunction · 0.85

Calls 1

getComponentLViewByIndexFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…