Hi Michael,
For a very simple small controller there is not much of a difference. When
your code grows, the IIFEs makes it much more readable. And if also
encapsulates any helpers/extra functions you need. Also, you should never
create a global, just to grab your module.
Have a look at this:
{ function (){
/* ngInject */ //Use a tool to prevent mistakes in the injection array!
function aSample($parse, someService, someConstant) {
var vm = this;
vm.calc = calculateSomething
}
function calculateSomething(number) {
// well, this can/should be more then a oneLiner ;)
return number * number +5;
}
angular
.module("myApp")
.controller('aSample', aSample)
}());
The idea is to keep your indentations as low as possible. This leads to
much easier to read and reason about code. There are more reasons to be
found in the style-guide Luis linked to.
Regards
Sander
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.