I am new to AngularJS and I am curious about the default dependencies that are injected. In my exploration of code, I have noticed that sometimes dependencies are explicitly listed in advance, while other times they are not. For instance:
someModule.controller('MyController', ['$scope', 'someService', function($scope, someService) {
// ...
}]);
Produces the same outcome as:
someModule.controller('MyController', function($scope, someService) {
// ...
});
How does this mechanism work? Does Angular assume that the modules being injected have the same names as the variables in the parameters?
Furthermore, interestingly enough, if you do specify the dependencies to be injected, you must include all of them and in the correct order, otherwise nothing will function properly. For example, consider this faulty code:
someModule.controller('MyController', ['someService', '$scope', function($scope, someService) {
// It won't generate any errors, but it also won't load the dependencies correctly
}]);
Could someone please explain how this entire process operates? Thank you in advance for your assistance!