How can I determine if an angular factory/service has been previously injected

I have an angular factory that performs some tasks upon injection into other objects. In some cases, I inject the factory using $injector.get() and in other cases, it is injected through the function declaration of the controller, service, etc.

I would like to determine if the factory has previously been injected. I could implement a Boolean value on the angular module and then trip the flag during factory initialization, but that seems clunky.

Is there a list of objects that have been previously injected during the life-cycle of an angular module?

Thoughts?


You can try using the $injector service.
Although you can't specifically see if it has been injected and is currently in use, you can see if the service exists using:

$injector.has('serviceName') 
链接地址: http://www.djcxy.com/p/77840.html

上一篇: 工厂模式。 何时使用工厂方法?

下一篇: 我如何确定以前是否注入过角度工厂/服务