MCPcopy Index your code
hub / github.com/angular/angular / getParentInjectorLocation

Function getParentInjectorLocation

packages/core/src/render3/di.ts:258–296  ·  view source on GitHub ↗
(tNode: TNode, lView: LView)

Source from the content-addressed store, hash-verified

256 * to find the LView containing the parent inject AND the index of the injector within that LView.
257 */
258export function getParentInjectorLocation(tNode: TNode, lView: LView): RelativeInjectorLocation {
259 if (tNode.parent && tNode.parent.injectorIndex !== -1) {
260 // If we have a parent `TNode` and there is an injector associated with it we are done, because
261 // the parent injector is within the current `LView`.
262 return tNode.parent.injectorIndex as RelativeInjectorLocation; // ViewOffset is 0
263 }
264
265 // When parent injector location is computed it may be outside of the current view. (ie it could
266 // be pointing to a declared parent location). This variable stores number of declaration parents
267 // we need to walk up in order to find the parent injector location.
268 let declarationViewOffset = 0;
269 let parentTNode: TNode | null = null;
270 let lViewCursor: LView | null = lView;
271
272 // The parent injector is not in the current `LView`. We will have to walk the declared parent
273 // `LView` hierarchy and look for it. If we walk of the top, that means that there is no parent
274 // `NodeInjector`.
275 while (lViewCursor !== null) {
276 parentTNode = getTNodeFromLView(lViewCursor);
277
278 if (parentTNode === null) {
279 // If we have no parent, than we are done.
280 return NO_PARENT_INJECTOR;
281 }
282
283 ngDevMode && parentTNode && assertTNodeForLView(parentTNode!, lViewCursor[DECLARATION_VIEW]!);
284 // Every iteration of the loop requires that we go to the declared parent.
285 declarationViewOffset++;
286 lViewCursor = lViewCursor[DECLARATION_VIEW];
287
288 if (parentTNode.injectorIndex !== -1) {
289 // We found a NodeInjector which points to something.
290 return (parentTNode.injectorIndex |
291 (declarationViewOffset <<
292 RelativeInjectorLocationFlags.ViewOffsetShift)) as RelativeInjectorLocation;
293 }
294 }
295 return NO_PARENT_INJECTOR;
296}
297/**
298 * Makes a type or an injection token public to the DI system by adding it to an
299 * injector's bloom filter.

Callers 4

parentInjectorMethod · 0.90
getInjectorParentFunction · 0.90

Calls 2

assertTNodeForLViewFunction · 0.90
getTNodeFromLViewFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…