I put focus on component element in dev tools and can do following:
ng.probe($0)
to get the special object "DebugElement". Now we can get its injector:
ng.probe($0).injector
now I would like to get a dependancy that is defined on this component. Dependancy is defined like a class, so I should do something like so:
ng.probe($0).injector.get(MyService)
BUT! Service is not defined in console scope. If I make it a string:
ng.probe($0).injector.get('MyService')
obviously it also does not work.
I'm trying to do reverse engineering on ReflectiveInjector.get, but no luck for now. Any ideas?
We have to pass token to
injector.get
method as it was declared. We can't use string if we declared class as token.Angular keeps providers declared within component in ngfactory Plunker
And it uses elementInjector to get dependency.
DebugElement
gets information about tokens provided to current nodeAfter we declared provider within
providers
array of component metadata the token becomes available inproviderTokens
array.So we can get dependency by writing
See also