0

I am trying to create a service in a module which is dependent on another service in another module but the services have the same name. Consider the following example:

angular.module('module1',[]).factory('log', [function () {
    return { show: false, msg: "" };
}]);

angular.module('module2', ['module1']).factory('log', ['log', function (log) {
    return { show: false, msg: log.msg + "" };
}]);

angular.module('myapp', ['module2']);

When I implement the above code get: Error: [$injector:cdep] Circular dependency found: log

I understand that services are singleton in angular [1] and the dependency injection follows last one wins convention [2]. Seems to me that in 'module2', 'log' that gets injected is itself hence the circular dependency. How do I inject 'log' from 'module1'?

Community
  • 1
  • 1
mxp
  • 180
  • 6
  • Is it necessary that you have to keep the name log for both of your services? – BKM Mar 18 '14 at 04:36
  • Yes, both of the service needs to have the same name. I want to extend the functionality of 'module1' and not make changes to 'myapp' other than update the dependencies. I know that having different service names would prevent this issue, it is how my app is at the moment. – mxp Mar 18 '14 at 05:54
  • I think this is a shortcoming of angular if there is no way to refer to a service with fully qualified name (something like module name + service name). – mostruash Apr 19 '15 at 12:18

1 Answers1

0

Old question but I solved it then using decorators.

mxp
  • 180
  • 6