fix(ivy): update ViewContainerRef to get the correct parentInjector (#35013)
PR Close #35013
This commit is contained in:

committed by
Andrew Kushnir

parent
519e9e1ae8
commit
b8ffcf973c
@ -12,8 +12,10 @@ import {DECLARATION_VIEW, LView, T_HOST} from './interfaces/view';
|
||||
import {getParentInjectorViewOffset} from './util/injector_utils';
|
||||
|
||||
/**
|
||||
* Unwraps a parent injector location number to find the view offset from the current injector,
|
||||
* then walks up the declaration view tree until the TNode of the parent injector is found.
|
||||
* If `startTNode.parent` exists and has an injector, returns TNode for that injector.
|
||||
* Otherwise, unwraps a parent injector location number to find the view offset from the current
|
||||
* injector, then walks up the declaration view tree until the TNode of the parent injector is
|
||||
* found.
|
||||
*
|
||||
* @param location The location of the parent injector, which contains the view offset
|
||||
* @param startView The LView instance from which to start walking up the view tree
|
||||
@ -23,14 +25,17 @@ import {getParentInjectorViewOffset} from './util/injector_utils';
|
||||
export function getParentInjectorTNode(
|
||||
location: RelativeInjectorLocation, startView: LView, startTNode: TNode): TElementNode|
|
||||
TContainerNode|null {
|
||||
// If there is an injector on the parent TNode, retrieve the TNode for that injector.
|
||||
if (startTNode.parent && startTNode.parent.injectorIndex !== -1) {
|
||||
// view offset is 0
|
||||
const injectorIndex = startTNode.parent.injectorIndex;
|
||||
let parentTNode = startTNode.parent;
|
||||
while (parentTNode.parent != null && injectorIndex == parentTNode.injectorIndex) {
|
||||
parentTNode = parentTNode.parent;
|
||||
let tNode = startTNode.parent;
|
||||
// If tNode.injectorIndex === tNode.parent.injectorIndex, then the index belongs to a parent
|
||||
// injector.
|
||||
while (tNode.parent != null && injectorIndex == tNode.parent.injectorIndex) {
|
||||
tNode = tNode.parent;
|
||||
}
|
||||
return parentTNode;
|
||||
return tNode;
|
||||
}
|
||||
let viewOffset = getParentInjectorViewOffset(location);
|
||||
// view offset is 1
|
||||
|
Reference in New Issue
Block a user