MCPcopy
hub / github.com/angular/angular / findViaDirective

Function findViaDirective

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

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

(lView: LView, directiveInstance: {})

Source from the content-addressed store, hash-verified

289 * Locates the directive within the given LView and returns the matching index
290 */
291function findViaDirective(lView: LView, directiveInstance: {}): number {
292 // if a directive is monkey patched then it will (by default)
293 // have a reference to the LView of the current view. The
294 // element bound to the directive being search lives somewhere
295 // in the view data. We loop through the nodes and check their
296 // list of directives for the instance.
297 let tNode = lView[TVIEW].firstChild;
298 while (tNode) {
299 const directiveIndexStart = tNode.directiveStart;
300 const directiveIndexEnd = tNode.directiveEnd;
301 for (let i = directiveIndexStart; i < directiveIndexEnd; i++) {
302 if (lView[i] === directiveInstance) {
303 return tNode.index;
304 }
305 }
306 tNode = traverseNextElement(tNode);
307 }
308 return -1;
309}
310
311/**
312 * Returns a list of directives applied to a node at a specific index. The list includes

Callers 1

getLContextFunction · 0.85

Calls 1

traverseNextElementFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…