I'm contemplating the value of writing angular code in different ways. One way is like this:
(function(angular, module) {
'use strict';
module.controller('MyCtrl', function($scope) {
// maybe utilize helperFunction here
});
function helperFunction() {
...
}
})(angular, angular.module('myModule'));
Another way is by using an App
object to organize the app's components:
App = App || {};
App.myModule = App.myModule || angular.module('myModule', []);
App.myModule.controller('MyCtrl', function($scope) {
'use strict'
// maybe utilize helperFunction here
function helperFunction() {
...
}
});
And then there's the more traditional approach:
angular.module('myModule').controller('MyCtrl', function($scope) {
'use strict'
// maybe utilize helperFunction here
function helperFunction() {
...
}
});
These are three possible ways (excluding requirejs) of structuring angular app code that I'm considering. While I typically use the last method, I'm curious if there are any advantages to the first two approaches. Perhaps there are specific scenarios where they prove to be more beneficial, which I may not be aware of.