General rule of thumb: First parameter is the name, second parameter is the the list of dependencies.
AngularJs, in general, has a very standard way of doing things. All declarations of angular objects follow the same convention:
angular.Object(NameOfObject,ArrayOfDependencies[])
where NameOfObject must be a string and ArrayOfDependencies is an array that contains either string or callback functions.
For example, if you want to declare an angular module with a name called myApp that depends on another angular module with the name of ngAnimate, you do the following:
angular.module('myApp',['ngAnimate']);
If you can't visualize it, let's breakdown into parts. The following code is the same as the single line code above.
var myModuleName = "myApp"; //this is your app name
var myDependenciesArray= ['ngAnimate']; // this is a list of dependencies your app is gonna depend on
angular.module(myModuleName,myDependenciesArray); //voila, module declared!
To answer your question, you will need to know what type of dependencies can be injected to which angular objects. You must not confuse.
module can only take in injection of another module, and cannot take in service types (or provider types to be exact).The following syntax is correct:
angular.module('module1',[]);
angular.module('module2',['module1']) // this is okay, module 2 depends on module1.
If you however do this:
angular.module('module2',['$http']) //this is NOT okay
You will get [$injector:modulerr] thrown by angular because $http is a service name and not a module name.
For the same reason, if you are not declaring a module, then you cannot inject a module in that declaration but have to inject services instead. The following syntax is correct:
angular.module('demo')
.controller('myCtrl',['$scope',function($scope){}] // this is okay, your controller depends on the $scope service
If you however do this:
angular.module('demo')
.controller('myCtrl',['ngResource']) // this is NOT okay
You will get [$injector:unpr] thrown by angular, stating that no such provider is found.
Let's answer your questions:
Q: Do you need to inject all your dependencies?
A: Definitely, as long as you need them. But make sure you inject them at the correct position.
Q: If dependencies are only passed into the function and not first declared in an array does this mean the libraries are not preloaded, is there a benefit to doing this?
A: As I have mentioned, the second argument of an angular object can take in an array, and that array can take in callback functions. If you however provide only one callback function, you will have problems later when you minify your JavaScript code.
Your app will break when javascript is minified if you write like this:
angular.module('myApp')
.controller('demoCtrl',function($scope){}); //will break
Your app will not break when javascript is minified if you write like this:
angular.module('myApp')
.controller('demoCtrl',['$scope',function($scope){}]
Q: Is there any difference in the way these modules are declared?
A: No. Look at the following:
angular.module('myApp',[])
.controller('demoCtrl',['$scope',function($scope){}]
The above code can be written like this, and they are the same:
var app = angular.module('myApp',[]);
app.controller('demoCtrl',['$scope',function($scope){}]