MCPcopy Create free account
hub / github.com/angular/angular / findViaComponent

Function findViaComponent

packages/core/src/render3/context_discovery.ts:250–270  ·  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

248 * Locates the component within the given LView and returns the matching index
249 */
250function findViaComponent(lView: LView, componentInstance: {}): number {
251 const componentIndices = lView[TVIEW].components;
252 if (componentIndices) {
253 for (let i = 0; i < componentIndices.length; i++) {
254 const elementComponentIndex = componentIndices[i];
255 const componentView = getComponentLViewByIndex(elementComponentIndex, lView);
256 if (componentView[CONTEXT] === componentInstance) {
257 return elementComponentIndex;
258 }
259 }
260 } else {
261 const rootComponentView = getComponentLViewByIndex(HEADER_OFFSET, lView);
262 const rootComponent = rootComponentView[CONTEXT];
263 if (rootComponent === componentInstance) {
264 // we are dealing with the root element here therefore we know that the
265 // element is the very first element after the HEADER data in the lView
266 return HEADER_OFFSET;
267 }
268 }
269 return -1;
270}
271
272/**
273 * 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