2

I am creating a angular module MyModule. The module contains a number of sub-modules.

angular.module('MyModule', [
  'MyModule.SubModule1',
  'MyModule.SubModule2',
  'MyModule.SubModule3'
]);

angular.module('MyModule.SubModule1', [
  'MyModule.Util'
]);

As you can see, there is the module MyModule.Util provides helper functions, which is actually written in a factory. No matter I explicit export MyModule.Util or not, it will be exported along with all my modules.

But I want this MyModule.Util only be used by sub-modules internally. Is that possible?

stanleyxu2005
  • 8,081
  • 14
  • 59
  • 94
  • I think you can not do untill we think some hack.. here some what related thing http://stackoverflow.com/a/16954554/2435473 – Pankaj Parkar Sep 12 '15 at 08:53
  • @PankajParkar My case can be sightly different/easier. I want to keep some helper functions in a private namespace, not controllers. – stanleyxu2005 Sep 12 '15 at 09:08

1 Answers1

1

Not possible in Angular as of today (v1.4.5)

Once you declare the module dependency, Angular imports all the modules from the dependency tree and makes them available to the app at large.

If you just need helper functions (as opposed to Angular services/directives/controllers), then you could just use a "private" function:

(function(angular){

  function privateHelperFunction1(){
  }

  angular.module("MyModule.SubModule1", [])
    .service("FooSvc", function(){
      this.doSomething = privateHelperFunction1;
    })

})(angular)
New Dev
  • 48,427
  • 12
  • 87
  • 129