I've seen two different approaches to organizing modules and controller structure in Angular 1.x.
The first, below, is the way I'm familiar with where you separate out the controllers into their own files and attach them to the parent angular module.
The second, create a large controller file to house related controllers and attach them to the parent controller, then inject the controller as a module into the parent angular module.
Which is more performant? Is there a difference?
App.js
angular
.module('mainApp', [
'a bunch of dependencies'
])
.run(['a bunch of dependencies', function(a bunch of dependencies){
myControllerA.js
angular
.module('mainApp')
.controller('myControllerA', ['a bunch of dependencies',
function(a bunch of dependencies) {
myControllerB.js
angular
.module('mainApp')
.controller('myControllerB', ['a bunch of dependencies',
function(a bunch of dependencies) {
App.js
var app = angular.module('mainApp', ['mainController', 'a bunch of dependencies']);
app.run(['a bunch of dependencies', function(mainController, a bunch of dependencies) {
mainController.js
var mainController = angular.module('mainController', [
'a bunch of dependencies'
]);
mainController.config(function(a bunch of dependencies) {
...
});
mainController.controller('controllerA', ['a bunch of dependencies', function(a bunch of dependencies) {
...
mainController.controller('controllerB', ['a bunch of dependencies', function(a bunch of dependencies) {
...