(I'm sorry that the next paragraph is going to be hard to parse. I find this always happens when describing DI).
I have an existing component, call it Widget
.
Widget
receives a Thingy
via ng2 DI. And Thingy
, in turn, receives a ThingyPart
via DI.
Now I am writing a new component, call it WidgetList
. WidgetList
is ultimately going to enter a loop and create multiple Widget
s. The main thing that is different about each of these Widget
s is that they each need to have a different ThingyPart
injected into their Thingy
. WidgetList
, and only WidgetList
, knows how to construct those ThingyPart
s, and it needs the current loop variable in order to construct.
Ultimately what needs to happen is that I need to Provide a different ThingyPart
per loop iteration. Is there any way to achieve this without touching Widget
?
Alternative question: I notice that I can receive the raw Injector in my WidgetList. Is there a way to dynamically add and remove the child injectors that my viewchildren see using the injector API? If there is, then I can create a new child injector in the loop and delete off the old one. (You know what would be cool? A "provide" template directive that does this for me.)