二者都
ElementRef
和
ViewContainerRef
是特殊的令牌,因为它们存储在TNode中。它们不像常规的DI令牌那样提供。
在这两种情况下,组件的NodeInjector都将为这些令牌提供值。
export function injectViewContainerRef(): ViewContainerRef {
const previousTNode = getCurrentTNode() as TElementNode | TElementContainerNode | TContainerNode;
return createContainerRef(previousTNode, getLView());
}
Source code
export function injectElementRef(): ElementRef {
return createElementRef(getCurrentTNode()!, getLView());
}
source code