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

Function createViewRef

packages/core/src/change_detection/change_detector_ref.ts:138–154  ·  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

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

Callers 1

injectChangeDetectorRefFunction · 0.85

Calls 2

isComponentHostFunction · 0.90
getComponentLViewByIndexFunction · 0.90

Tested by

no test coverage detected