1

I have a module that has a service defined as

angular.module('mean.system').service('helperService', ['$rootScope', '$q', '$log', function ($rootScope, $q, $log) {

I am defining another module that will use the same service. I want to inject this service into another module, is it valid to do something like

angular.module('mean.system', 'myModule2').service('helperService', ... (etc) ) {

1 Answer 1

4

In that case you should identify and separate all the shared parts of your app (services, controllers, directives, etc) and put them in their own module:

angular.module('shared.services').service('helperService', ... (etc) )...

And then inject that shared module in the modules that need them:

angular.module('mean.system', ['shared.services', other-dependencies...])
angular.module('myModule2', ['shared.services', other-dependencies...])

This way you can use the helperService (and all other parts added to the shared.services module) in your other modules.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.