Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to differentiate between namespaces of injected modules in AngularJS?

Lets say I have a controller, which depends on two modules that both contain a directive or a service with the same name. Can I specify which one exactly should be used?

angular.module('myApp', ['secondModule', 'thirdModule'])
    .controller('Ctrl1', ['$scope', 'myService', function(scope, myService){
        scope.user = myService.getUser();   
        console.log(myService); 
}]);

In this case both secondModule and thirdModule have a service called myService. But only the one from the thirdModule will be used in this example. I tried putting something like secondModule.myService as a dependency for Ctrl1, but it wouldn't work. Is there some kind of namespacing in AngularJS?

like image 691
Helios Avatar asked Nov 03 '22 04:11

Helios


1 Answers

At the moment, no, there is no module based namespacing. You'll have to avoid collisions on your own.

I believe there was some discussion about this, but I can't find it at the moment.

like image 142
satchmorun Avatar answered Nov 09 '22 11:11

satchmorun