I have a service:
angular.module('USC').service('TemplateService', function() {});
That I would like to use before I manually bootstrap my Angular project:
angular.bootstrap(document, ['USC']);
Is this possible? I know I can call var service = angular.bootstrap().get(); for Angular provided services, but how would I call a custom one before the module was initialized?
If it is OK to have a different instance of the service than the one that will be used by the app itself, you can achieve what you want like this:
angular.injector(['ng', 'yourApp']).get('SomeService').doStuff();
See, also, this short demo.
As you can see the service is re-instantiated (so counter starts from 0) for use within the Angular app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With