Is it posible to get all injected services/injectable that extends a particular class?

12 views
Skip to first unread message

Christophe HOARAU

unread,
Feb 21, 2019, 11:37:29 PM2/21/19
to Angular and AngularJS discussion
Hello,

I'm looking for a way to retrieve in a component the list of all loaded services/injectable that extends a particular class.

I need this because this component will be used in multiple independent applications that are sharing codes, but all applications does not load all services.
I'm looking for an "easy way" to get a list of all the services, which are extending a specific class, that are currently loaded in the application.

Thanks for your help.
Best regards.

Sander Elias

unread,
Feb 25, 2019, 8:46:57 AM2/25/19
to Angular and AngularJS discussion
Hi Christophe, 

If you use lazy-loaded services, you can just use your service wherever you see fit, and the CLI will make sure it will end up in the correct bundle.
While it is possible to inspect the injector tree, it needs a load of manual labor to get usable results. 

Regards
Sander

Sander Elias

unread,
Feb 25, 2019, 8:48:34 AM2/25/19
to Angular and AngularJS discussion
You can learn about tree-shakable providers here

Christophe HOARAU

unread,
Mar 10, 2019, 1:50:14 AM3/10/19
to Angular and AngularJS discussion
Hello,

Sorry for the late response.
I'm couldn't find out how to list all injected services.
Docs about tree-shakable providers only provide data about how to create them, not how to get and parse the list of injected services.

Thanks
Best regards
Reply all
Reply to author
Forward
0 new messages