I find myself in a situation where I need to manually retrieve objects from the Angular $injector.
Up until now, I have been using the following approach:
var injector = angular.injector(['app.service', 'ng']);
var myService = injector.get('myService');
While this method worked well, I recently encountered an issue. It seems that every time I call angular.injector
, the run()
method of the app.service module is triggered. This has led to my app initialization logic getting executed multiple times unnecessarily.
Should I consider moving my app bootstrapping code out of the run() method, or is there a way to obtain the $injector without triggering the run() method?
Additionally, I am concerned about the potential performance implications of frequently calling the injector. Is this a valid concern?