Imagine I go ahead and create an AngularJs service. Then I attach it to my module like this:
angular.module('fooModule').service('myService', function(){
var service = {
logSomething: function() {
console.log('Service logged something');
}
};
return service;
});
Interesting, right? It's just sitting there alongside constants, factories, providers, you name it. But why is there a need to inject these services, constants, etc into controllers afterwards? Is it similar to the concept of "using" in C# - simply to prevent any potential conflicts with variable or function names? However, if that's the case, why do I still have to write myService.logSomething()
, which essentially solves the namespace problem?
Could it possibly have something to do with speeding up the loading process? That doesn't seem entirely plausible though.