I have a complex scenario which I need help with.
I have a directive (called TagDirective
) that is placed on multiple elements all over my app. I have another directive (QueryDirective
) which needs to reference all instances of TagDirective
that exist on its host element, as well as on all the elements above it in the hierarchy.
Example:
<div appTag="a">
<div appTag="b">
<div appTag="c">
<div appTag="d">
<div appQuery>
<!-- In here I want to have a reference to TagDirectives instances
d,c,b,a -->
</div>
</div>
</div>
<div appTag="e">
<div appTag="f">
<div appTag="g">
<div appTag="h">
<div appQuery>
<!-- In here I want to have a reference to TagDirectives instances
h,g,f,e,b,a -->
</div>
</div>
</div>
<div appQuery>
<!-- In here I want to have a reference to TagDirectives instances
f,e,b,a -->
</div>
</div>
</div>
</div>
</div>
I know I can obtain a reference to the TagDirective
on the host element alone by having the injector provide it in the constructor of QueryDirective
, I also know I can get the next higher instance by injecting ViewContainerRef
and using its parentInjector
member to request an instance of type TagDirective
.
However, I haven't found a way to go further up the tree, and collect all the instances all the way up to the root.
How would I achieve that? Thanks!