Let\'s say I have made a module with a service and a controller in Angular.js, I am able to access that service inside of the controller like so:
var myapp = ang
Angular simply parses the toString()
representation of the function for the names of dependencies. From the docs:
In JavaScript calling
toString()
on a function returns the function definition. The definition can then be parsed and the function arguments can be extracted.
However, note that this approach will fail if your code is minified. For that reason, Angular supports an alternative (I would suggest always using it) syntax, using an array:
myapp.controller('mainController', ["$scope", "Service", function($scope, Service) {
$scope.greeting= Service.example;
}]);