MCPcopy
hub / github.com/angular/angular / getInjectionTokens

Function getInjectionTokens

packages/core/src/render3/util/discovery_utils.ts:155–176  ·  view source on GitHub ↗
(element: Element)

Source from the content-addressed store, hash-verified

153 * @param element Element for which the injection tokens should be retrieved.
154 */
155export function getInjectionTokens(element: Element): any[] {
156 const context = getLContext(element)!;
157 const lView = context ? context.lView : null;
158 if (lView === null) return [];
159 const tView = lView[TVIEW];
160 const tNode = tView.data[context.nodeIndex] as TNode;
161 const providerTokens: any[] = [];
162 const startIndex = tNode.providerIndexes & TNodeProviderIndexes.ProvidersStartIndexMask;
163 const endIndex = tNode.directiveEnd;
164 for (let i = startIndex; i < endIndex; i++) {
165 let value = tView.data[i];
166 if (isDirectiveDefHack(value)) {
167 // The fact that we sometimes store Type and sometimes DirectiveDef in this location is a
168 // design flaw. We should always store same type so that we can be monomorphic. The issue
169 // is that for Components/Directives we store the def instead the type. The correct behavior
170 // is that we should always be storing injectable type in this location.
171 value = value.type;
172 }
173 providerTokens.push(value);
174 }
175 return providerTokens;
176}
177
178/**
179 * Retrieves directive instances associated with a given DOM node. Does not include

Callers 2

providerTokensMethod · 0.90

Calls 3

getLContextFunction · 0.90
isDirectiveDefHackFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…