AngularJS - module dependencies, naming clash AngularJS - module dependencies, naming clash javascript javascript

AngularJS - module dependencies, naming clash


You can request a factory of a certain module explicitly (without dependency injection):

var injector = angular.injector(['thirdParty1']);var hello1 = injector.get('hello');var injector = angular.injector(['thirdParty2']);var hello2 = injector.get('hello');

You can also use this, to wrap the third party factories into own factories:

angular.module('own1', ['thirdParty1']).factory('hello1', function () {  var injector = angular.injector(['thirdParty1']);  var hello = injector.get('hello');  return hello;});angular.module('own2', ['thirdParty2']).factory('hello2', function () {  var injector = angular.injector(['thirdParty2']);  var hello = injector.get('hello');  return hello;});

This allows you to use hello1 and hello2 in all other parts of your application.


Since there is no built-in name spacing of modules (or components of modules) the best way to achieve your goal is to use a unique naming convention for your modules. Most libraries for angular do this, and then you should be good to go.

Besides encapsulating your applications behavior, modules help testing and mocking your application.

I dont think it is possible for angular to differentiate between two components that are named the same (I think this changes with angular 2). And I might argue that two components that are named the same might do the same and you should look why you need both?