MCPcopy
hub / github.com/angular/angular / createViewRef

Function createViewRef

packages/core/src/change_detection/change_detector_ref.ts:139–155  ·  view source on GitHub ↗

* Creates a ViewRef and stores it on the injector as ChangeDetectorRef (public alias). * * @param tNode The node that is requesting a ChangeDetectorRef * @param lView The view to which the node belongs * @param isPipe Whether the view is being injected into a pipe. * @returns The ChangeDetector

(tNode: TNode, lView: LView, isPipe: boolean)

Source from the content-addressed store, hash-verified

137 * @returns The ChangeDetectorRef to use
138 */
139function createViewRef(tNode: TNode, lView: LView, isPipe: boolean): ChangeDetectorRef {
140 if (isComponentHost(tNode) && !isPipe) {
141 // The LView represents the location where the component is declared.
142 // Instead we want the LView for the component View and so we need to look it up.
143 const componentView = getComponentLViewByIndex(tNode.index, lView); // look down
144 return new ViewRef(componentView, componentView);
145 } else if (
146 tNode.type &
147 (TNodeType.AnyRNode | TNodeType.AnyContainer | TNodeType.Icu | TNodeType.LetDeclaration)
148 ) {
149 // The LView represents the location where the injection is requested from.
150 // We need to locate the containing LView (in case where the `lView` is an embedded view)
151 const hostComponentView = lView[DECLARATION_COMPONENT_VIEW]; // look up
152 return new ViewRef(hostComponentView, lView);
153 }
154 return null!;
155}

Callers 1

injectChangeDetectorRefFunction · 0.85

Calls 2

isComponentHostFunction · 0.90
getComponentLViewByIndexFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…