* 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)
| 137 | * @returns The ChangeDetectorRef to use |
| 138 | */ |
| 139 | function 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 | } |
no test coverage detected
searching dependent graphs…