The best way to define controllers, directives, factories, etc. - this is
define the names of your modules in a separate file
app.module.js
angular.module("myapp",[]);
a separate file is created for the controllers (depending on your requirement, even you can create 1 file for 1 controller)
some.controller.js
angular.module("myapp").controller('someCtrl'['$scope', function($scope){ }]); angular.module("myapp").controller('someOtherCtrl'['$scope', function($scope){ }]);
Note:
Two types you can write a controller
TYPE1 (not recommended)
.controller('ctrlName', function($scope){ });
TYPE2 (recommended)
.controller('ctrlName', ['$scope', function($scope){ }]);
Cause
So, as you can see in TYPE2, we pass the controller dependencies in an array, so when we compile our program, angular will give a name, for example: a to $ scope inside the function () and treat it like $ scope.
With TYPE1, you need to follow a certain order, defining the controller dependency, otherwise angular will go through an error, because in this approach angular just treats the first dependency as $ anchcope, the second as $ scope, etc ...
For instance:
you cannot transfer dependencies with your controller like this
.controller('ctrlName', function($http, $scope) { });
it will cause an error
if you determine how
.controller('ctrlName', function($scope, $http) { });
this will work fine since it wants angular.