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

Function getParentInjectorLocation

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

Source from the content-addressed store, hash-verified

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