What is the best way to write a controller in AngularJS? I've seen it written many different ways and it's confusing on which way is better then the rest.
Personally I write it like this,
var app = angular.module('app'); // app is created elsewhere, just referencing it
var MainController = function($scope) {
// Do Stuff
}
app.controller("MainController", [MainController]);
I think writing it this way is the cleanest way to write it. Everything is separated so it's easier to read.
The most common way I've seen it written is like this,
app.controller("EventController", function EventController($scope) {
// Do stuff
}
I would like to know, if there any pitfalls in the future that would happen if I keep writing them the way I prefer? Why is one way better than the other?