There are three ways to annotate function dependencies:
First: explicit and exact with parameter names:
app.controller('ACtrl', function($scope, $http, $q) {
This means that the function has parameter names that must correspond to the names of already registered services / providers. Caveat : if you minimize the file (uglify to save space), you will lose the parameter names, and therefore it will be broken - it will not work (it will complain).
The second method allows you to select the names of the services to enter as string literals (since the string literal is a value, it is never reduced):
var myfunc = function($s, $http, $q) { //do your stuff here }; myfunc.$inject = ['$scope', '$http', '$q']; app.controller('ACtrl', myfunc);
This means that Angular reads the $ injection property of the function and corresponds to the formal parameters not by name, but by value in the same position of the array. That way, $ scope will be in $ s, even if you shrink the file. If $ injection does not exist in this function, then you will return to the first and not recommended case.
The third is similar to the second (that is, it will indicate dependencies in rows and will resist guessing):
var myfunc = function($s, $http, $q) { //do your stuff here } app.controller('ACtrl', ['$scope', '$http', '$q', myfunc]);
Note that the last element of the array is a call function. It looks a little creepy, but it is consistent. Angular does this: if the controller is an array, the last element is exposed - it will be a function. The first elements (the remaining array) are processed exactly as if they were the value of $inject in the function.
Controllers and vendors must have a name to reference them - I used "ACtrl" as the name of the controller. This is not a function name, but an internal name for use in Dependency Injection (for providers) and more, such as ngRoute (for controllers).
The name declaration is the first border of the posting that you request. Using them in any of the three forms of Injection Dependency is the second link of such posting .
Remember : AdvancedGithubUser is a registered provider, equal to $http . The only difference is that $http is built into Angular, while AdvancedGithubUser is not. Characters starting with a dollar sign should be reserved for Angular, but this is not a requirement - just good practice. AdvancedGithubUser was created (in an external module) with something like:
app.service('AdvancedGithubUser', AdvancedGithubUser);