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

Function findViaDirective

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

273 * Locates the directive within the given LView and returns the matching index
274 */
275function findViaDirective(lView: LView, directiveInstance: {}): number {
276 // if a directive is monkey patched then it will (by default)
277 // have a reference to the LView of the current view. The
278 // element bound to the directive being search lives somewhere
279 // in the view data. We loop through the nodes and check their
280 // list of directives for the instance.
281 let tNode = lView[TVIEW].firstChild;
282 while (tNode) {
283 const directiveIndexStart = tNode.directiveStart;
284 const directiveIndexEnd = tNode.directiveEnd;
285 for (let i = directiveIndexStart; i < directiveIndexEnd; i++) {
286 if (lView[i] === directiveInstance) {
287 return tNode.index;
288 }
289 }
290 tNode = traverseNextElement(tNode);
291 }
292 return -1;
293}
294
295/**
296 * 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