Hi Dominic,

If you use the function approach, you do define your controllers on the 
global scope. This is a bad idea, and there are
multiple ways to work around that.
One way you have mentioned yourself, and that is directly using the 
controller method of angular.module
Tonypee explained another method, and here I will give you a third.

Have a look at this:

(function () {
    "use strict";

    function AppController ($scope)  {
        // a lot of controller code here.
    }

    angular.module('sample') // here I use an already created module 'sample'! 
        .controller('Appcontroller', [$scope, AppController]);
}());

This way, you wrap your controller(s) inside an IIFE 
<http://benalman.com/news/2010/11/immediately-invoked-function-expression/>, 
so you are not leaking into the global scope.
you are using a normal JS function to define your controller, at last, you 
hook it up to angular

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 http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to